Imports ccapps.persistent.Retention_Handler
Imports System.Xml
Imports System.Web.Services.Protocols
Imports System.Runtime.Serialization.Formatters
Imports System.Text.RegularExpressions


Namespace Web.page


    Partial Class RetentionToolAssignOffer
        Inherits [lib].BasePage

#Region " Web Form Designer Generated Code "

        'This call is required by the Web Form Designer.
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

        End Sub
        Protected WithEvents pnlMiddle As System.Web.UI.WebControls.Panel
        Protected WithEvents lblRetHistory As System.Web.UI.WebControls.LinkButton


        Protected WithEvents pblPBCIslemTuru As System.Web.UI.WebControls.Panel


        'NOTE: The following placeholder declaration is required by the Web Form Designer.
        'Do not delete or move it.
        Private designerPlaceholderDeclaration As System.Object

        Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
            'CODEGEN: This method call is required by the Web Form Designer
            'Do not modify it using the code editor.
            InitializeComponent()
        End Sub

#End Region

        Private p_user As String
        Private retention_hitcount As String
        Private aktif_hat = 0


        Public Sub RegisterScript(ByVal script As String)
            Me.Page.RegisterStartupScript(Guid.NewGuid.ToString(), "<SCRIPT LANGUAGE=""JavaScript"">" & script & "</SCRIPT>")
        End Sub

        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            PageTitle = "Teklif Verme İşlemleri"
            p_user = Session("user")

            If (Not Page.IsPostBack) Then

                Session("RTML_USER_PROFILE_ID") = Nothing
                Session("RTML_USER_PROFILE_NAME") = Nothing
                initializeSessionVariables()
                rbTeklifVermeTipiBind()
                ddlRetNedeni.Items.Clear()
                ddlRetNedeni.Items.Add(New ListItem("Seçiniz", "-1"))
                getCallTypesBind()

                Dim tdsec1 As HtmlTableCell = Page.FindControl("tdNumaraSec")
                tdNumaraSec.Attributes("style") = "DISPLAY: none"

                Dim tblSirketBazliBilgiler As HtmlTable = Page.FindControl("tblSirketBazliBilgiler")
                tblSirketBazliBilgiler.Attributes("style") = "DISPLAY: none"

                Dim tblRetentionHistory As HtmlTable = Page.FindControl("tblRetentionHistory")
                tblRetentionHistory.Attributes("style") = "DISPLAY: none"

                Dim TRHatBazliBilgiler As HtmlTableRow = Page.FindControl("TRHatBazliBilgiler")
                TRHatBazliBilgiler.Attributes("style") = "DISPLAY: none"

                Dim HREFHatBazliSelection As HtmlControl = Page.FindControl("HREFHatBazliSelection")
                HREFHatBazliSelection.Attributes("style") = "DISPLAY: none"

            Else

                Dim myDiv As HtmlControl = Page.FindControl("myDiv")
                myDiv.Controls.Clear()
                renderContractBasedInfo()


            End If

        End Sub


        Protected Sub changeRetentionHist(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HrefRetentionHistory.ServerClick

            Dim tblRetentionHistory As HtmlTable = Page.FindControl("tblRetentionHistory")

            If tblRetentionHistory.Attributes("style") = "DISPLAY: none" Then
                tblRetentionHistory.Attributes("style") = ""

            Else
                tblRetentionHistory.Attributes("style") = "DISPLAY: none"

            End If

        End Sub

        Private Sub renderContractBasedInfo()


            Dim myDiv As HtmlControl = Page.FindControl("myDiv")

            If Not (Session("RTAO_Selected_MSISDN_INFO") Is Nothing) Then

                For Each drS As DataRow In Session("RTAO_Selected_MSISDN_INFO").Rows

                    myDiv.Controls.Add(drawContractInfos(drS("MSISDN").ToString()))

                Next

            End If

        End Sub


        Protected Sub changeHatBazli(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HrefHatBazli.ServerClick

            Dim TRHatBazliBilgiler As HtmlTableRow = Page.FindControl("TRHatBazliBilgiler")
            Dim HREFHatBazliSelection As HtmlControl = Page.FindControl("HREFHatBazliSelection")

            If TRHatBazliBilgiler.Attributes("style") = "DISPLAY: none" Then
                TRHatBazliBilgiler.Attributes("style") = ""
                If rbTeklifVermeTipi.SelectedValue <> 1 Then
                    HREFHatBazliSelection.Attributes("style") = ""
                End If
            Else
                TRHatBazliBilgiler.Attributes("style") = "DISPLAY: none"
                If rbTeklifVermeTipi.SelectedValue <> 1 Then
                    HREFHatBazliSelection.Attributes("style") = "DISPLAY: none"
                End If
            End If

        End Sub

        Protected Sub changeSirketBazli(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HrefSirketBazli.ServerClick

            Dim tblSirketBazliBilgiler As HtmlTable = Page.FindControl("tblSirketBazliBilgiler")

            If tblSirketBazliBilgiler.Attributes("style") = "DISPLAY: none" Then
                tblSirketBazliBilgiler.Attributes("style") = ""
            Else
                tblSirketBazliBilgiler.Attributes("style") = "DISPLAY: none"
            End If

        End Sub

        Protected Sub setHatBazliSelection(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HREFHatBazliSelection.ServerClick

            Dim HatBazliSelectionList As HtmlTableCell = Page.FindControl("HatBazliSelectionList")

            If HatBazliSelectionList.Attributes("style") = "DISPLAY: none" Then
                HatBazliSelectionList.Attributes("style") = ""
            Else
                HatBazliSelectionList.Attributes("style") = "DISPLAY: none"
            End If

        End Sub



        Private Sub initializeSessionVariables()

            Session("rtao_customerid") = Nothing
            Session("rtao_custcode") = Nothing
            Session("rtao_srnumber") = Nothing
            Session("rtao_retcustomertypeid") = Nothing
            Session("rtao_customer_type") = Nothing
            Session("RTML_Selected_MSISDN") = Nothing
            Session("RTAO_Selected_MSISDN_INFO") = Nothing
            Session("rtao_msisdn") = Nothing
            Session("RTAO_RETID") = Nothing
            Session("rtao_msisdn_status") = Nothing
            Session("rtao_fpm_payer_coid") = Nothing
            If Not Session("RTAO_Session_MSISDN") Is Nothing Then

                Dim dt As DataTable = Session("RTAO_Session_MSISDN")

                If dt.Rows.Count > 0 Then

                    Session("RTAO_MSISDN" & dt.Rows(0)("MSISDN")) = Nothing

                End If

                Session("RTAO_Session_MSISDN") = Nothing

            End If

        End Sub

        Private Sub CustomerBasedInfoBind(ByVal p_customer_id As Integer)

            Dim dt As DataTable = getCustomerBasedInfo(p_customer_id, Session("rtao_fpm_payer_coid"), p_user, Session("user"))

            If dt.Rows.Count > 0 Then

                tbSon3AyFaturaOrt.Text = NVL(dt.Rows(0)("SON3AYFATORT"))
                If (rbTeklifVermeTipi.SelectedValue = 2 Or rbTeklifVermeTipi.SelectedValue = 4) Then
                    tbAktifHatAdeti.Text = aktif_hat
                Else
                    tbAktifHatAdeti.Text = NVL(dt.Rows(0)("AKTIFHAT"))
                End If

                tbLineFreezeHatAdeti.Text = NVL(dt.Rows(0)("LINEFREEZEHAT"))
                tbOdenmemisFatura.Text = NVL(dt.Rows(0)("ODENMEMISFATURA"))
                tbSon3AyDeaktifHatAdeti.Text = NVL(dt.Rows(0)("SON3AYDEAKTIFHAT"))
                tbRiskGrubu.Text = NVL(dt.Rows(0)("RISKGRUBU"))
                tbOtomatikOdemeTalimati.Text = NVL(dt.Rows(0)("OTOMATIKODEME"))
                tbSessizHatYuzdesi.Text = NVL(dt.Rows(0)("SESSIZHATYUZDESI"))
                tbTenure.Text = NVL(dt.Rows(0)("TENURE"))
                tbSmy.Text = NVL(dt.Rows(0)("SMY"))
                tbDeaktivasyonCezaTutari.Text = NVL(dt.Rows(0)("DEAKTCEZA"))
                tbDeaktHat.Text = NVL(dt.Rows(0)("DEAKTHAT"))
                tbHotlineHat.Text = NVL(dt.Rows(0)("HOTLINEHAT"))
                tbSuspendHat.Text = NVL(dt.Rows(0)("SUSPENDHAT"))
                tbCustSegment.Text = NVL(dt.Rows(0)("CUSTSEGMENT"))
                tbTariffandDate.Text = NVL(dt.Rows(0)("TARIFFNAME"))

                If NVL(dt.Rows(0)("PBC3DEACTLC")) = "-1" Then
                    lblPBCType3.Visible = False
                    lblPBCType3.Text = ""
                Else
                    lblPBCType3.Visible = True
                    lblPBCType3.Text = "( Hat Adeti Oransal Taahhütü İptal Edilebilir Hat Sayısı : " & NVL(dt.Rows(0)("PBC3DEACTLC")) & " )"
                End If

            End If

            dgFaturanlaKazanBind(p_customer_id)

        End Sub

        Private Sub dgFaturanlaKazanBind(ByVal p_customer_id As Integer, Optional ByVal pageIndex As Integer = 0)

            Dim dt As DataTable = getFaturanlaKazan(p_customer_id, Session("user"))
            If dt.Rows.Count > 0 Then
                dgFaturanlaKazan.Visible = True
                dgFaturanlaKazan.CurrentPageIndex = pageIndex
                dgFaturanlaKazan.DataSource = dt
                dgFaturanlaKazan.DataBind()
                lblFaturaKazan.Text = "Faturanla Kazan Taahhütü"

                Dim TRSirketFaturanlaKazan As HtmlTableRow = Page.FindControl("TRSirketFaturanlaKazan")
                TRSirketFaturanlaKazan.Attributes("style") = "PADDING-LEFT: 5px; PADDING-RIGHT: 5px"

            Else
                dgFaturanlaKazan.Visible = False
                lblFaturaKazan.Text = "Faturanla Kazan Taahhütü bulunmamaktadır!."

                Dim TRSirketFaturanlaKazan As HtmlTableRow = Page.FindControl("TRSirketFaturanlaKazan")
                TRSirketFaturanlaKazan.Attributes("style") = "DISPLAY: none"

            End If
        End Sub


        Private Sub dgRetentionHistBind(ByVal p_customer_id As Integer, ByVal p_msisdn As String)

            Dim dt As DataTable = getRetentionHist(p_customer_id, p_msisdn, Session("rtao_fpm_payer_coid"), Session("user"))
            If dt.Rows.Count > 0 Then
                dgRetentionHist.Visible = True
                dgRetentionHist.DataSource = dt
                dgRetentionHist.DataBind()
                lblRetHist.Text = ""
                For Each dgi As DataGridItem In dgRetentionHist.Items

                    If dgi.Cells(1).Text = "&nbsp;" Then

                        dgi.Cells(6).Enabled = False
                        dgi.Cells(4).Text = "N/A"
                        dgi.Cells(4).Enabled = False

                    End If

                    dgi.Cells(7).Text = "<a href=""#"" onclick=""openSiebelDetails('RetentionToolRetentionSiebelDetails.aspx?RetentionID=" & dgi.Cells(0).Text & "')"" >Siebel Bilgisi</a>"

                Next

                ' Session.Add("txtNumofRetentions", dt.Rows.Count)

            Else
                dgRetentionHist.Visible = False
                lblRetHist.Text = "Daha önce retention işlemi bulunmamaktadır!."
            End If
            txtNumofRetentions.Text = dt.Rows.Count
            Session.Add("txtNumofRetentions", dt.Rows.Count)
        End Sub

        Private Sub lbMsisdnListBind(ByVal p_custcode As String)

            lbMsisdnList.Items.Clear()

            'Dim dt As DataTable = getMsisdnList(p_custcode, Session("rtao_fpm_payer_coid"), Session("user"))
            Dim dt As DataTable
            If (rbTeklifVermeTipi.SelectedValue = 2 Or rbTeklifVermeTipi.SelectedValue = 4) Then
                dt = getMsisdnList(p_custcode, 0, Session("user"))
                aktif_hat = dt.Rows.Count
            Else
                dt = getMsisdnList(p_custcode, Session("rtao_fpm_payer_coid"), Session("user"))
                aktif_hat = dt.Rows.Count
            End If
            If dt.Rows.Count > 0 Then
                lbMsisdnList.Enabled = False
                'For Each dr As DataRow In dt.Rows
                '    lbMsisdnList.Items.Add(New ListItem(dr("STATUS").ToString(), dr("MSISDN").ToString()))
                'Next
                lblMsisdnList.Text = ""
                lblMsisdnList.Visible = False
                lbtnMsisdnList.Text = "<b><a href=""#"" onclick=""openMsisdnList('RetentionToolMsisdnList.aspx?CUSTCODE=" & Session("rtao_custcode") & "')"" >Numara Seç</a></b>"
                lbMsisdnList.Visible = False
            Else
                lbMsisdnList.Enabled = False
                lbtnMsisdnList.Enabled = False
                lblMsisdnList.Text = "MSISDN bulunamadı!."
                lblMsisdnList.Visible = True
            End If
        End Sub


        Private Sub lbMsisdnInfoListBind(ByVal p_custcode As String)

            lbMsisdnInfoList.Items.Clear()
            'Dim dt As DataTable = getMsisdnList(p_custcode, Session("rtao_fpm_payer_coid"), Session("user"))
            Dim dt As DataTable
            If (rbTeklifVermeTipi.SelectedValue = 2 Or rbTeklifVermeTipi.SelectedValue = 4) Then
                dt = getMsisdnList(p_custcode, 0, Session("user"))
            Else
                dt = getMsisdnList(p_custcode, Session("rtao_fpm_payer_coid"), Session("user"))
            End If
            If dt.Rows.Count > 0 Then

                For Each dr As DataRow In dt.Rows
                    lbMsisdnInfoList.Items.Add(New ListItem(dr("STATUS").ToString(), dr("MSISDN").ToString()))
                Next

            Else
                'msisdn bulunmamadı!.
            End If
        End Sub



        Private Sub dgFaturanlaKazan_PageIndexChanged(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs)

            dgFaturanlaKazanBind(Session("rtao_customerid"), e.NewPageIndex)
        End Sub
        Private Sub dbTekliferReRender()
            'Dim celcount As Integer
            'celcount = 2
            'For Each dgi As DataGridItem In dgTeklifler.Items

            'If dgi.Cells(1).Text = "&nbsp;" Then

            ' dgi.Cells(6).Enabled = False
            '  dgi.Cells(4).Text = "N/A"
            '   dgi.Cells(4).Enabled = False

            'End If

            'dgi.Cells(6).Enabled = False

            'dgi.Cells(2).Text = "<a href=""#"" onclick=""alert('Teklif verilecektir. Onaylıyor musunuz?')"
            'dgi.Cells(2).Text = "<a id=""dgTeklifler__ctl" & celcount & "_lbOfferAdvantage"" href=""javascript:alert('Teklif verilecektir. Lütfen Teklif sonuç mesajı gelene kadar başka işlem yapmadan bekleyiniz. '); __doPostBack('dgTeklifler$_ctl" & celcount & "$lbOfferAdvantage','')"" >Teklifi Ver</a>"
            'celcount = celcount + 1
            'Next
        End Sub

        Private Sub dgTekliflerBind(ByVal p_document_status As Integer)

            Dim p_customer_id As Integer = Session("rtao_customerid")
            Dim p_ret_cust_type_id As Integer = Session("rtao_retcustomertypeid")
            Dim p_ret_user_prof_id As Integer = Session("RTML_USER_PROFILE_ID")
            Dim p_offer_assign_type As Integer = rbTeklifVermeTipi.SelectedValue
            Dim p_msisdn As String
            If Session("rtao_msisdn") = "" Then
                p_msisdn = "-1"
            Else
                p_msisdn = Session("rtao_msisdn")
            End If

            Dim p_msisdn_list As String = ":"
            Dim dtSM As DataTable = Session("RTML_Selected_MSISDN")
            If dtSM Is Nothing Then
                Return
            End If
            If dtSM.Rows.Count > 0 Then
                For Each drSM As DataRow In dtSM.Rows
                    p_msisdn_list &= drSM("MSISDN").ToString() & ":"
                Next
            End If
            p_msisdn_list &= "-1:"

            Dim dt As DataTable = getOffers(p_customer_id, Session("rtao_fpm_payer_coid"), p_msisdn, p_msisdn_list, p_ret_cust_type_id, p_ret_user_prof_id, p_document_status, p_offer_assign_type, Session("user"))
            If dt.Rows.Count > 0 Then


                If NVL(dt.Rows(0)("OFFERID")) = -1 Then 'Error Indicator
                    lblOfferList.Text = NVL(dt.Rows(0)("OFFERNAME")) 'Error Name
                    dgTeklifler.Visible = False
                    pnlUserNotes.Visible = False
                    tbUserNotes1.Visible = False
                    lblUserNotes.Visible = False
                Else
                    lblOfferList.Text = ""
                    For Each dr As DataRow In dt.Rows
                        ': TODO()



                        If NVL(dr("OFFERID")) = -2 Then 'Warning Indicator
                            lblOfferList.Text = NVL(dr("OFFERNAME")) 'Warning Name
                            dr.Delete()
                        End If

                    Next


                    dgTeklifler.Visible = True
                    pnlUserNotes.Visible = True
                    tbUserNotes1.Visible = True
                    lblUserNotes.Visible = True
                    dgTeklifler.DataSource = dt
                    dgTeklifler.DataBind()
                    dgTeklifler.Enabled = True


                    'Dim celcount As Integer
                    'celcount = 2
                    'For Each dgi As DataGridItem In dgTeklifler.Items

                    'If dgi.Cells(1).Text = "&nbsp;" Then

                    ' dgi.Cells(6).Enabled = False
                    '  dgi.Cells(4).Text = "N/A"
                    '   dgi.Cells(4).Enabled = False

                    'End If

                    'dgi.Cells(6).Enabled = False

                    'dgi.Cells(2).Text = "<a href=""#"" onclick=""alert('Teklif verilecektir. Onaylıyor musunuz?')"
                    'dgi.Cells(2).Text = "<a id=""dgTeklifler__ctl" & celcount & "_lbOfferAdvantage"" href=""javascript:alert('Teklif verilecektir. Lütfen Teklif sonuç mesajı gelene kadar başka işlem yapmadan bekleyiniz. '); __doPostBack('dgTeklifler$_ctl" & celcount & "$lbOfferAdvantage','')"" >Teklifi Ver</a>"
                    'celcount = celcount + 1
                    'Next
                    If NVL(dt.Rows(0)("CHECKSUSPEND")) = "BNP Suspend - Tanımlanamaz." Then
                        dgTeklifler.Enabled() = False
                        lblOfferList.Text = "BNP Suspend - Tanımlanamaz."
                        Message = "alert('BNP Suspend durumunda olduğu için teklif verilemez, BNP suspendden çıkması durumunda verilebilecek teklifler aşağıdadır');"
                        Return
                    ElseIf NVL(dt.Rows(0)("CHECKSUSPEND")) = "Suspend - Tanımlanamaz." Then
                        dgTeklifler.Enabled() = False
                        lblOfferList.Text = "Suspend - Tanımlanamaz."
                    ElseIf NVL(dt.Rows(0)("CHECKSUSPEND")) = "FRAUD Suspend - Tanımlanamaz." Then
                        dgTeklifler.Enabled() = False
                        lblOfferList.Text = "FRAUD Suspend - Tanımlanamaz."
                    End If

                    'Dim i As Integer

                    'Response.Write("adets:" & dgTeklifler.Controls.Count)


                    'For i = 1 To dt.Rows.Count Step 1
                    'Dim x As String
                    'Dim mycontrol As LinkButton

                    'x = "dgTeklifler__ctl" & Convert.ToString(i) & "_lbOfferAdvantage"
                    'Response.Write("xadets:" & x)
                    ''Response.Write("name: " & dgTeklifler.Controls(i - 1).ID.ToString)
                    'mycontrol = Page.FindControl(x)
                    ''dgTeklifler__ctl3_lbOfferAdvantage()
                    ''Page.FindControl("lbOfferAdvantage")
                    ''dgTeklifler.FindControl("lbOfferAdvantage")
                    'If Not (mycontrol Is Nothing) Then
                    'mycontrol.Attributes.Add("onClick", "return window.confirm('Are you sure you want to do this?'")
                    'End If

                    'Next



                End If

            Else
                lblOfferList.Text = "Müşteriye uygun Teklif bulunmamaktadır!."
                dgTeklifler.Visible = False
                pnlUserNotes.Visible = False
                tbUserNotes1.Visible = False
                lblUserNotes.Visible = False
            End If
            If Trim(tbSrNumber.Text) = "" Then

                '  dgTeklifler.Enabled = False
                cbTeklifVermeme.Enabled = False
                pnlUserNotes.Visible = False
                tbUserNotes1.Visible = False
                lblUserNotes.Visible = False

            End If
        End Sub


        Private Sub ddlRetNedeniBind(ByVal p_customer_type_id As Integer)

            ' ddlRetNedeni.Items.Clear()
            'ddlRetNedeni.Items.Add(New ListItem("Seçiniz", "0"))
            p_customer_type_id = -1 'for all customer type tek tip reasons
            Dim dt As DataTable = getRetentionReasons(p_customer_type_id)

            If dt.Rows.Count > 0 Then
                For Each dr As DataRow In dt.Rows
                    ddlRetNedeni.Items.Add(New ListItem(dr("REASON").ToString(), dr("REASONID").ToString()))
                Next
            End If
        End Sub

        Private Sub ddlTeklifVermemeBind()

            ddlTeklifVermeme.Items.Clear()
            ddlTeklifVermeme.Items.Add(New ListItem("Seçiniz", "0"))

            Dim dt As DataTable = getOfferNonAssignmentReasons()

            If dt.Rows.Count > 0 Then
                For Each dr As DataRow In dt.Rows
                    ddlTeklifVermeme.Items.Add(New ListItem(dr("NONASSIGNRS").ToString(), dr("NONASSIGNRSID").ToString()))
                Next
            End If
        End Sub


        Private Sub getCallTypesBind()

            ddlAramaTipi.Items.Clear()
            ddlAramaTipi.Items.Add(New ListItem("Seçiniz", "0"))

            Dim dt As DataTable = getCallTypes()

            If dt.Rows.Count > 0 Then
                For Each dr As DataRow In dt.Rows
                    ddlAramaTipi.Items.Add(New ListItem(dr("CALLTYPE").ToString(), dr("CALLTYPEID").ToString()))
                Next
            End If
        End Sub

        Private Sub rbTeklifVermeTipiBind()

            rbTeklifVermeTipi.Items.Clear()

            Dim dt As DataTable = getUserBasedAssignTypes(CType(p_user, String))
            Dim count As Integer = 0
            If dt.Rows.Count > 0 Then
                For Each dr As DataRow In dt.Rows

                    If dr("TYPE").ToString() = "1" Then
                        rbTeklifVermeTipi.Items.Add(New ListItem(dr("ASSIGNTYPE").ToString(), dr("ASSIGNTYPEID").ToString()))
                        If count = 0 Then
                            rbTeklifVermeTipi.SelectedValue = dr("ASSIGNTYPEID").ToString()
                            rbTeklifVermeTipiChange(rbTeklifVermeTipi.SelectedValue)
                        End If
                        count += 1
                    Else

                        Session("RTML_USER_PROFILE_ID") = dr("ASSIGNTYPEID").ToString()
                        Session("RTML_USER_PROFILE_NAME") = dr("ASSIGNTYPE").ToString()

                        If dr("ASSIGNTYPEID").ToString() = "0" Then
                            lblTeklifVermeTipi.Text = "İşlem yapmaya yetkiniz yoktur!."
                        End If

                        tbRole.Text = dr("ASSIGNTYPE").ToString()

                    End If
                Next
            Else
                lblTeklifVermeTipi.Text = "İşlem yapmaya yetkiniz yoktur!."
            End If
        End Sub



        Private Sub rbTeklifVermeTipiChange(ByVal selectedval As String)
            divRetentionCeza.Visible = False
            Select Case selectedval

                Case "1" 'Mass/Inst Bir(1) Hata Teklif
                    lblCustcode.Enabled = True
                    tbCustcode.Enabled = True
                    lblSrNumber.Enabled = True
                    tbSrNumber.Enabled = True
                    lblMSISDN.Enabled = True
                    tbMSISDN.Enabled = True
                    btnGoruntule.Enabled = True
                    pnlMsisdnList.Visible = False
                    Dim HatBazliSelectionList As HtmlTableCell = Page.FindControl("HatBazliSelectionList")
                    HatBazliSelectionList.Attributes("style") = "DISPLAY: none"
                    Dim tdNumaraSec As HtmlTableCell = Page.FindControl("tdNumaraSec")
                    tdNumaraSec.Attributes("style") = "DISPLAY: none"
                    Dim tdBaslik1 As HtmlTableCell = Page.FindControl("tdBaslik1")
                    tdBaslik1.Attributes("colspan") = "5"

                Case "2" 'Sirkete Teklif
                    lblCustcode.Enabled = True
                    tbCustcode.Enabled = True
                    lblSrNumber.Enabled = True
                    tbSrNumber.Enabled = True
                    lblMSISDN.Enabled = False
                    tbMSISDN.Enabled = False
                    btnGoruntule.Enabled = True
                    pnlMsisdnList.Visible = False
                    Dim HatBazliSelectionList As HtmlTableCell = Page.FindControl("HatBazliSelectionList")
                    HatBazliSelectionList.Attributes("style") = ""
                    Dim tdNumaraSec As HtmlTableCell = Page.FindControl("tdNumaraSec")
                    tdNumaraSec.Attributes("style") = "DISPLAY: none"
                    Dim tdBaslik1 As HtmlTableCell = Page.FindControl("tdBaslik1")
                    tdBaslik1.Attributes("colspan") = "5"

                Case "3" 'Sirketin Bir(1) Hattina Teklif
                    lblCustcode.Enabled = False
                    tbCustcode.Enabled = False
                    lblSrNumber.Enabled = True
                    tbSrNumber.Enabled = True
                    lblMSISDN.Enabled = True
                    tbMSISDN.Enabled = True
                    btnGoruntule.Enabled = True
                    pnlMsisdnList.Visible = False
                    Dim HatBazliSelectionList As HtmlTableCell = Page.FindControl("HatBazliSelectionList")
                    HatBazliSelectionList.Attributes("style") = ""
                    Dim tdNumaraSec As HtmlTableCell = Page.FindControl("tdNumaraSec")
                    tdNumaraSec.Attributes("style") = "DISPLAY: none"
                    Dim tdBaslik1 As HtmlTableCell = Page.FindControl("tdBaslik1")
                    tdBaslik1.Attributes("colspan") = "5"

                Case "4" 'Sirketin Birden Fazla Hattina Teklif
                    lblCustcode.Enabled = True
                    tbCustcode.Enabled = True
                    lblSrNumber.Enabled = True
                    tbSrNumber.Enabled = True
                    lblMSISDN.Enabled = False
                    tbMSISDN.Enabled = False
                    btnGoruntule.Enabled = True
                    pnlMsisdnList.Visible = True
                    Dim HatBazliSelectionList As HtmlTableCell = Page.FindControl("HatBazliSelectionList")
                    HatBazliSelectionList.Attributes("style") = ""
                    Dim tdNumaraSec As HtmlTableCell = Page.FindControl("tdNumaraSec")
                    tdNumaraSec.Attributes("style") = ""
                    Dim tdBaslik1 As HtmlTableCell = Page.FindControl("tdBaslik1")
                    tdBaslik1.Attributes("colspan") = "6"


            End Select


        End Sub

        Private Sub rbTeklifVermeTipi_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbTeklifVermeTipi.SelectedIndexChanged

            rbTeklifVermeTipiChange(rbTeklifVermeTipi.SelectedValue)
            initalizeAreas()

        End Sub

        Private Function drawContractInfos(ByVal p_msisdn As String) As HtmlTable

            Dim tbTaeh As System.Web.UI.WebControls.TextBox = New System.Web.UI.WebControls.TextBox
            tbTaeh.ReadOnly = True
            Dim tbOdenmemisFaturaHat As System.Web.UI.WebControls.TextBox = New System.Web.UI.WebControls.TextBox
            tbOdenmemisFaturaHat.ReadOnly = True
            Dim tbRiskGrubuHat As System.Web.UI.WebControls.TextBox = New System.Web.UI.WebControls.TextBox
            tbRiskGrubuHat.ReadOnly = True
            Dim tbOtomatikOdeme As System.Web.UI.WebControls.TextBox = New System.Web.UI.WebControls.TextBox
            tbOtomatikOdeme.ReadOnly = True
            Dim tbTenureHat As System.Web.UI.WebControls.TextBox = New System.Web.UI.WebControls.TextBox
            tbTenureHat.ReadOnly = True
            Dim tbSessizlik As System.Web.UI.WebControls.TextBox = New System.Web.UI.WebControls.TextBox
            tbSessizlik.ReadOnly = True
            Dim tbSegment As System.Web.UI.WebControls.TextBox = New System.Web.UI.WebControls.TextBox
            tbSegment.ReadOnly = True
            Dim tbFaturaTutari As System.Web.UI.WebControls.TextBox = New System.Web.UI.WebControls.TextBox
            tbFaturaTutari.ReadOnly = True
            Dim tbOutMou As System.Web.UI.WebControls.TextBox = New System.Web.UI.WebControls.TextBox
            tbOutMou.ReadOnly = True
            Dim tbInMou As System.Web.UI.WebControls.TextBox = New System.Web.UI.WebControls.TextBox
            tbInMou.ReadOnly = True
            Dim tbDataUsage As System.Web.UI.WebControls.TextBox = New System.Web.UI.WebControls.TextBox
            tbDataUsage.ReadOnly = True
            Dim tbArpu As System.Web.UI.WebControls.TextBox = New System.Web.UI.WebControls.TextBox
            tbArpu.ReadOnly = True
            Dim tbDeakCezaTutari As System.Web.UI.WebControls.TextBox = New System.Web.UI.WebControls.TextBox
            tbDeakCezaTutari.ReadOnly = True
            Dim tbAktNedeni As System.Web.UI.WebControls.TextBox = New System.Web.UI.WebControls.TextBox
            tbAktNedeni.ReadOnly = True
            Dim tbRMoInvoiceTL As System.Web.UI.WebControls.TextBox = New System.Web.UI.WebControls.TextBox
            tbRMoInvoiceTL.ReadOnly = True
            Dim tbRMoInvoiceDkAdMb As System.Web.UI.WebControls.TextBox = New System.Web.UI.WebControls.TextBox
            tbRMoInvoiceDkAdMb.ReadOnly = True
            Dim tbRMtVoiceTL As System.Web.UI.WebControls.TextBox = New System.Web.UI.WebControls.TextBox
            tbRMtVoiceTL.ReadOnly = True
            Dim tbRMtVoiceDkAdMb As System.Web.UI.WebControls.TextBox = New System.Web.UI.WebControls.TextBox
            tbRMtVoiceDkAdMb.ReadOnly = True
            Dim tbRMoSmsTL As System.Web.UI.WebControls.TextBox = New System.Web.UI.WebControls.TextBox
            tbRMoSmsTL.ReadOnly = True
            Dim tbRMoSmsDkAdMb As System.Web.UI.WebControls.TextBox = New System.Web.UI.WebControls.TextBox
            tbRMoSmsDkAdMb.ReadOnly = True
            Dim tbRGprsTL As System.Web.UI.WebControls.TextBox = New System.Web.UI.WebControls.TextBox
            tbRGprsTL.ReadOnly = True
            Dim tbRGprsDkAdMb As System.Web.UI.WebControls.TextBox = New System.Web.UI.WebControls.TextBox
            tbRGprsDkAdMb.ReadOnly = True
            Dim tbTarife As System.Web.UI.WebControls.TextBox = New System.Web.UI.WebControls.TextBox
            tbTarife.ReadOnly = True
            Dim lblTaahPaket As System.Web.UI.WebControls.Label = New System.Web.UI.WebControls.Label
            Dim dgHat As System.Web.UI.WebControls.DataGrid = New System.Web.UI.WebControls.DataGrid
            Dim tbRMtSmsTL As System.Web.UI.WebControls.TextBox = New System.Web.UI.WebControls.TextBox
            tbRMtSmsTL.ReadOnly = True
            Dim tbRMtSmsDkAdMb As System.Web.UI.WebControls.TextBox = New System.Web.UI.WebControls.TextBox
            tbRMtSmsDkAdMb.ReadOnly = True
            Dim tbMvpncode As System.Web.UI.WebControls.TextBox = New System.Web.UI.WebControls.TextBox
            tbMvpncode.ReadOnly = True
            Dim tbActDate As System.Web.UI.WebControls.TextBox = New System.Web.UI.WebControls.TextBox
            tbActDate.ReadOnly = True

            Dim tblHat As HtmlTable = New HtmlTable
            tblHat.Attributes("border") = "0"
            tblHat.Attributes("cellSpacing") = "1"
            tblHat.Attributes("cellPadding") = "1"
            tblHat.Attributes("width") = "100%"


            Dim tblR1 As HtmlTableRow = New HtmlTableRow
            Dim tblR1C1 As HtmlTableCell = New HtmlTableCell
            tblR1C1.Attributes("class") = "prompt"
            tblR1C1.Attributes("colSpan") = "2"
            tblR1C1.Attributes("align") = "center"
            tblR1C1.InnerHtml = "<span  style=""font-weight:bold;"">Hat Bilgileri : " & p_msisdn & "</span>"
            tblR1.Controls.Add(tblR1C1)
            Dim tblR1C2 As HtmlTableCell = New HtmlTableCell
            tblR1C2.Attributes("class") = "prompt"
            tblR1C2.Attributes("colSpan") = "2"
            tblR1C2.Attributes("align") = "center"
            tblR1C2.InnerHtml = "<span style=""font-weight:bold;"">Son 3 Ay Ortalamaları</span>"
            tblR1.Controls.Add(tblR1C2)
            Dim tblR1C3 As HtmlTableCell = New HtmlTableCell
            tblR1C3.Attributes("class") = "prompt"
            tblR1C3.Attributes("colSpan") = "3"
            tblR1C3.Attributes("align") = "center"
            tblR1C3.InnerHtml = "<span  style=""font-weight:bold;"">Son 3 Ay Roaming Kullanım Ortalamaları</span>"
            tblR1.Controls.Add(tblR1C3)
            tblHat.Controls.Add(tblR1)


            Dim tblR2 As HtmlTableRow = New HtmlTableRow
            Dim tblR2C1 As HtmlTableCell = New HtmlTableCell
            tblR2C1.Attributes("class") = "solbaslik"
            tblR2.Controls.Add(tblR2C1)
            Dim tblR2C8 As HtmlTableCell = New HtmlTableCell
            tblR2C8.Attributes("class") = "solbaslik"
            tblR2.Controls.Add(tblR2C8)
            Dim tblR2C3 As HtmlTableCell = New HtmlTableCell
            tblR2C3.Attributes("class") = "solbaslik"
            tblR2C3.InnerHtml = "<span>Fatura Tutarı</span>"
            tblR2.Controls.Add(tblR2C3)
            Dim tblR2C4 As HtmlTableCell = New HtmlTableCell
            tblR2C4.Attributes("class") = "input"
            tblR2C4.Controls.Add(tbFaturaTutari)
            tblR2.Controls.Add(tblR2C4)
            Dim tblR2C5 As HtmlTableCell = New HtmlTableCell
            tblR2C5.Attributes("class") = "solbaslik"
            tblR2C5.InnerHtml = "<span>Arama (SES)</span>" 'MO Voice
            tblR2.Controls.Add(tblR2C5)
            Dim tblR2C6 As HtmlTableCell = New HtmlTableCell
            tblR2C6.Attributes("class") = "input"
            tblR2C6.Controls.Add(tbRMoInvoiceTL)
            tblR2.Controls.Add(tblR2C6)
            Dim tblR2C7 As HtmlTableCell = New HtmlTableCell
            tblR2C7.Attributes("class") = "input"
            tblR2C7.Controls.Add(tbRMoInvoiceDkAdMb)
            tblR2.Controls.Add(tblR2C7)
            tblHat.Controls.Add(tblR2)


            Dim tblR3 As HtmlTableRow = New HtmlTableRow
            Dim tblR3C1 As HtmlTableCell = New HtmlTableCell
            tblR3C1.Attributes("class") = "solbaslik"
            tblR3C1.InnerHtml = "<span>Tarife ve Geçiş Tarihi</span>"
            tblR3.Controls.Add(tblR3C1)
            Dim tblR3C2 As HtmlTableCell = New HtmlTableCell
            tblR3C2.Attributes("class") = "input4"
            tblR3C2.Controls.Add(tbTarife)
            tblR3.Controls.Add(tblR3C2)
            Dim tblR3C3 As HtmlTableCell = New HtmlTableCell
            tblR3C3.Attributes("class") = "solbaslik"
            tblR3C3.InnerHtml = "<span>Yapılan Toplam Arama</span>" 'Outgoing MOU
            tblR3.Controls.Add(tblR3C3)
            Dim tblR3C4 As HtmlTableCell = New HtmlTableCell
            tblR3C4.Attributes("class") = "input"
            tblR3C4.Controls.Add(tbOutMou)
            tblR3.Controls.Add(tblR3C4)
            Dim tblR3C5 As HtmlTableCell = New HtmlTableCell
            tblR3C5.Attributes("class") = "solbaslik"
            tblR3C5.InnerHtml = "<span>Aranma (SES)</span>" 'MT Voice
            tblR3.Controls.Add(tblR3C5)
            Dim tblR3C6 As HtmlTableCell = New HtmlTableCell
            tblR3C6.Attributes("class") = "input"
            tblR3C6.Controls.Add(tbRMtVoiceTL)
            tblR3.Controls.Add(tblR3C6)
            Dim tblR3C7 As HtmlTableCell = New HtmlTableCell
            tblR3C7.Attributes("class") = "input"
            tblR3C7.Controls.Add(tbRMtVoiceDkAdMb)
            tblR3.Controls.Add(tblR3C7)
            tblHat.Controls.Add(tblR3)


            Dim tblR4 As HtmlTableRow = New HtmlTableRow
            Dim tblR4C1 As HtmlTableCell = New HtmlTableCell
            tblR4C1.Attributes("class") = "solbaslik"
            tblR4.Controls.Add(tblR4C1)
            Dim tblR4C2 As HtmlTableCell = New HtmlTableCell
            tblR4C2.Attributes("class") = "input"
            tblR4C2.InnerHtml = ""
            tblR4.Controls.Add(tblR4C2)
            Dim tblR4C3 As HtmlTableCell = New HtmlTableCell
            tblR4C3.Attributes("class") = "solbaslik"
            tblR4C3.InnerHtml = "<span>Gelen Toplam Arama</span>" 'Incoming MOU
            tblR4.Controls.Add(tblR4C3)
            Dim tblR4C4 As HtmlTableCell = New HtmlTableCell
            tblR4C4.Attributes("class") = "input"
            tblR4C4.Controls.Add(tbInMou)
            tblR4.Controls.Add(tblR4C4)
            Dim tblR4C5 As HtmlTableCell = New HtmlTableCell
            tblR4C5.Attributes("class") = "solbaslik"
            tblR4C5.InnerHtml = "<span>Giden (SMS)</span>" 'MO Sms
            tblR4.Controls.Add(tblR4C5)
            Dim tblR4C6 As HtmlTableCell = New HtmlTableCell
            tblR4C6.Attributes("class") = "input"
            tblR4C6.Controls.Add(tbRMoSmsTL)
            tblR4.Controls.Add(tblR4C6)
            Dim tblR4C7 As HtmlTableCell = New HtmlTableCell
            tblR4C7.Attributes("class") = "input"
            tblR4C7.Controls.Add(tbRMoSmsDkAdMb)
            tblR4.Controls.Add(tblR4C7)
            tblHat.Controls.Add(tblR4)


            Dim tblR5 As HtmlTableRow = New HtmlTableRow
            Dim tblR5C1 As HtmlTableCell = New HtmlTableCell
            tblR5C1.Attributes("class") = "solbaslik"
            tblR5C1.InnerHtml = "<span>Segment</span>"
            tblR5.Controls.Add(tblR5C1)
            Dim tblR5C2 As HtmlTableCell = New HtmlTableCell
            tblR5C2.Attributes("class") = "input"
            tblR5C2.Controls.Add(tbSegment)
            tblR5.Controls.Add(tblR5C2)
            Dim tblR5C3 As HtmlTableCell = New HtmlTableCell
            tblR5C3.Attributes("class") = "solbaslik"
            tblR5C3.InnerHtml = "<span>Data Kullanımı</span>" 'Data Usage
            tblR5.Controls.Add(tblR5C3)
            Dim tblR5C4 As HtmlTableCell = New HtmlTableCell
            tblR5C4.Attributes("class") = "input"
            tblR5C4.Controls.Add(tbDataUsage)
            tblR5.Controls.Add(tblR5C4)
            Dim tblR5C5 As HtmlTableCell = New HtmlTableCell
            tblR5C5.Attributes("class") = "solbaslik"
            tblR5C5.InnerHtml = "<span>Gelen (SMS)</span>" 'MT Sms
            tblR5.Controls.Add(tblR5C5)
            Dim tblR5C6 As HtmlTableCell = New HtmlTableCell
            tblR5C6.Attributes("class") = "input"
            tblR5C6.Controls.Add(tbRMtSmsTL)
            tblR5.Controls.Add(tblR5C6)
            Dim tblR5C7 As HtmlTableCell = New HtmlTableCell
            tblR5C7.Attributes("class") = "input"
            tblR5C7.Controls.Add(tbRMtSmsDkAdMb)
            tblR5.Controls.Add(tblR5C7)
            tblHat.Controls.Add(tblR5)


            Dim tblR6 As HtmlTableRow = New HtmlTableRow
            Dim tblR6C1 As HtmlTableCell = New HtmlTableCell
            tblR6C1.Attributes("class") = "solbaslik"
            tblR6C1.InnerHtml = "<span>TAEH Tutarı</span>"
            tblR6.Controls.Add(tblR6C1)
            Dim tblR6C2 As HtmlTableCell = New HtmlTableCell
            tblR6C2.Attributes("class") = "input"
            tblR6C2.Controls.Add(tbTaeh)
            tblR6.Controls.Add(tblR6C2)
            Dim tblR6C3 As HtmlTableCell = New HtmlTableCell
            tblR6C3.Attributes("class") = "solbaslik"
            tblR6C3.InnerHtml = "<span>Ortalama Hat Geliri</span>" 'ARPU
            tblR6.Controls.Add(tblR6C3)
            Dim tblR6C4 As HtmlTableCell = New HtmlTableCell
            tblR6C4.Attributes("class") = "input4"
            tblR6C4.Controls.Add(tbArpu)
            tblR6.Controls.Add(tblR6C4)
            Dim tblR6C5 As HtmlTableCell = New HtmlTableCell
            tblR6C5.Attributes("class") = "solbaslik"
            tblR6C5.InnerHtml = "<span>GPRS</span>"
            tblR6.Controls.Add(tblR6C5)
            Dim tblR6C6 As HtmlTableCell = New HtmlTableCell
            tblR6C6.Attributes("class") = "input4"
            tblR6C6.Controls.Add(tbRGprsTL)
            tblR6.Controls.Add(tblR6C6)
            Dim tblR6C7 As HtmlTableCell = New HtmlTableCell
            tblR6C7.Attributes("class") = "input4"
            tblR6C7.Controls.Add(tbRGprsDkAdMb)
            tblR6.Controls.Add(tblR6C7)
            tblHat.Controls.Add(tblR6)
            tblHat.Controls.Add(tblR6)


            Dim tblR7 As HtmlTableRow = New HtmlTableRow
            Dim tblR7C1 As HtmlTableCell = New HtmlTableCell
            tblR7C1.Attributes("class") = "solbaslik"
            tblR7C1.InnerHtml = "<span>Ödenmemiş Fat. Top. </span>"
            tblR7.Controls.Add(tblR7C1)
            Dim tblR7C2 As HtmlTableCell = New HtmlTableCell
            tblR7C2.Attributes("class") = "input"
            tblR7C2.Controls.Add(tbOdenmemisFaturaHat)
            tblR7.Controls.Add(tblR7C2)
            Dim tblR7C3 As HtmlTableCell = New HtmlTableCell
            tblR7C3.Attributes("class") = "solbaslik"
            tblR7C3.InnerHtml = "<span>Aktivasyon Tarihi</span>"
            tblR7.Controls.Add(tblR7C3)
            Dim tblR7C4 As HtmlTableCell = New HtmlTableCell
            tblR7C4.Attributes("class") = "input"
            tblR7C4.Controls.Add(tbActDate)
            tblR7.Controls.Add(tblR7C4)
            Dim tblR7C5 As HtmlTableCell = New HtmlTableCell
            tblR7C5.Attributes("class") = "input"
            tblR7C5.Attributes("colSpan") = "2"
            tblR7.Controls.Add(tblR7C5)
            tblHat.Controls.Add(tblR7)


            Dim tblR8 As HtmlTableRow = New HtmlTableRow
            Dim tblR8C1 As HtmlTableCell = New HtmlTableCell
            tblR8C1.Attributes("class") = "solbaslik"
            tblR8C1.InnerHtml = "<span>Risk Grubu</span>"
            tblR8.Controls.Add(tblR8C1)
            Dim tblR8C2 As HtmlTableCell = New HtmlTableCell
            tblR8C2.Attributes("class") = "input"
            tblR8C2.Controls.Add(tbRiskGrubuHat)
            tblR8.Controls.Add(tblR8C2)
            Dim tblR8C3 As HtmlTableCell = New HtmlTableCell
            tblR8C3.Attributes("class") = "solbaslik"
            tblR8C3.InnerHtml = "<span>Abone Yaşı</span>" 'Tenure
            tblR8.Controls.Add(tblR8C3)
            Dim tblR8C4 As HtmlTableCell = New HtmlTableCell
            tblR8C4.Attributes("class") = "input"
            tblR8C4.Controls.Add(tbTenureHat)
            tblR8.Controls.Add(tblR8C4)
            Dim tblR8C6 As HtmlTableCell = New HtmlTableCell
            tblR8C6.Attributes("class") = "input"
            tblR8C6.Attributes("colSpan") = "2"
            tblR8C6.Attributes("style") = "BORDER-RIGHT-STYLE: none"
            tblR8C6.InnerHtml = "&nbsp"
            tblR8.Controls.Add(tblR8C6)
            Dim tblR8C5 As HtmlTableCell = New HtmlTableCell
            tblR8C5.Attributes("class") = "input"
            tblR8C5.Attributes("colSpan") = "1"
            tblR8C5.Attributes("align") = "center"
            Dim btnContractDeactCezaHesapla As Button = New Button
            btnContractDeactCezaHesapla.CssClass = "button01"
            btnContractDeactCezaHesapla.ID = "btnCezaHesapla" & p_msisdn
            btnContractDeactCezaHesapla.Text = "Ceza Hesapla"
            AddHandler btnContractDeactCezaHesapla.Click, AddressOf Contract_Deact_Ceza_Hesapla
            tblR8C5.Controls.Add(btnContractDeactCezaHesapla)
            'tblR8C5.Controls.Add(tblR8C5)
            tblR8.Controls.Add(tblR8C5)
            tblHat.Controls.Add(tblR8)


            Dim tblR9 As HtmlTableRow = New HtmlTableRow
            Dim tblR9C1 As HtmlTableCell = New HtmlTableCell
            tblR9C1.Attributes("class") = "solbaslik"
            tblR9C1.InnerHtml = "<span>Aktivasyon Nedeni</span>"
            tblR9.Controls.Add(tblR9C1)
            Dim tblR9C2 As HtmlTableCell = New HtmlTableCell
            tblR9C2.Attributes("class") = "input"
            tblR9C2.Controls.Add(tbAktNedeni)
            tblR9.Controls.Add(tblR9C2)
            Dim tblR9C3 As HtmlTableCell = New HtmlTableCell
            tblR9C3.Attributes("class") = "solbaslik"
            tblR9C3.InnerHtml = "<span>Sessizlik</span>"
            tblR9.Controls.Add(tblR9C3)
            Dim tblR9C4 As HtmlTableCell = New HtmlTableCell
            tblR9C4.Attributes("class") = "input4"
            tblR9C4.Controls.Add(tbSessizlik)
            tblR9.Controls.Add(tblR9C4)
            Dim tblR9C5 As HtmlTableCell = New HtmlTableCell
            tblR9C5.Attributes("class") = "solbaslik"
            tblR9C5.Attributes("colSpan") = "2"
            tblR9C5.InnerHtml = "<span>Deaktivasyon Ceza Tutarı</span>"
            tblR9.Controls.Add(tblR9C5)
            Dim tblR9C6 As HtmlTableCell = New HtmlTableCell
            tblR9C6.Attributes("class") = "input4"
            tblR9C6.Controls.Add(tbDeakCezaTutari)
            tblR9.Controls.Add(tblR9C6)
            tblHat.Controls.Add(tblR9)


            Dim tblR10 As HtmlTableRow = New HtmlTableRow
            Dim tblR10C1 As HtmlTableCell = New HtmlTableCell
            tblR10C1.Attributes("class") = "solbaslik"
            tblR10C1.InnerHtml = "<span>Otomatik Ödeme Tal.</span>"
            tblR10.Controls.Add(tblR10C1)
            Dim tblR10C2 As HtmlTableCell = New HtmlTableCell
            tblR10C2.Attributes("class") = "input"
            tblR10C2.Controls.Add(tbOtomatikOdeme)
            tblR10.Controls.Add(tblR10C2)
            Dim tblR10C3 As HtmlTableCell = New HtmlTableCell
            tblR10C3.Attributes("class") = "solbaslik"
            tblR10C3.InnerHtml = "<span>MVPN Kısa Kodu</span>"
            tblR10.Controls.Add(tblR10C3)
            Dim tblR10C4 As HtmlTableCell = New HtmlTableCell
            tblR10C4.Attributes("class") = "input"
            tblR10C4.Controls.Add(tbMvpncode)
            tblR10.Controls.Add(tblR10C4)
            Dim tblR10C5 As HtmlTableCell = New HtmlTableCell
            'tblR10C5.Attributes("class") = "solbaslik"
            tblR10.Controls.Add(tblR10C5)
            tblHat.Controls.Add(tblR10)


            Dim tblR13 As HtmlTableRow = New HtmlTableRow
            Dim tblR13C1 As HtmlTableCell = New HtmlTableCell
            tblR13C1.Attributes("class") = "solbaslik"
            tblR13C1.Attributes("colSpan") = "7"
            lblTaahPaket.Font.Bold = True
            tblR13C1.Controls.Add(lblTaahPaket)
            tblR13.Controls.Add(tblR13C1)
            tblHat.Controls.Add(tblR13)

            Dim dt As DataTable

            If Not (Session("RTAO_MSISDN" & p_msisdn) Is Nothing) Then
                dt = Session("RTAO_MSISDN" & p_msisdn)
            Else
                dt = getContractBasedInfo(p_msisdn, p_user, Session("rtao_customer_type"), Session("user"))
            End If

            If dt.Rows.Count > 0 Then

                Session("RTAO_MSISDN" & p_msisdn) = dt

                If Session("RTAO_Session_MSISDN") Is Nothing Then

                    Dim dtSM As DataTable = New DataTable
                    dtSM.Columns.Add(New DataColumn("MSISDN", GetType(String)))
                    Dim dtRowSM As DataRow = dtSM.NewRow()
                    dtRowSM.Item("MSISDN") = p_msisdn
                    dtSM.Rows.Add(dtRowSM)
                    Session("RTAO_Session_MSISDN") = dtSM

                Else

                    Dim dtSM As DataTable = Session("RTAO_Session_MSISDN")
                    Dim dtRowSM As DataRow = dtSM.NewRow()
                    dtRowSM.Item("MSISDN") = p_msisdn
                    dtSM.Rows.Add(dtRowSM)

                End If

                tbTarife.Text = NVL(dt.Rows(0)("TARIFF")) & " / " & NVL(dt.Rows(0)("TARIFFDATE"))
                tbOdenmemisFaturaHat.Text = NVL(dt.Rows(0)("ODENMEMIS"))
                tbRiskGrubuHat.Text = NVL(dt.Rows(0)("RISK"))
                tbAktNedeni.Text = NVL(dt.Rows(0)("AKTNEDENI"))
                tbOtomatikOdeme.Text = NVL(dt.Rows(0)("OTOMATIK"))
                tbSessizlik.Text = NVL(dt.Rows(0)("SESSIZLIK"))
                tbSegment.Text = NVL(dt.Rows(0)("SEGMENTNAME"))
                tbFaturaTutari.Text = NVL(dt.Rows(0)("FATURA"))
                tbOutMou.Text = NVL(dt.Rows(0)("OUTMOU"))
                tbInMou.Text = NVL(dt.Rows(0)("INMOU"))
                tbDataUsage.Text = NVL(dt.Rows(0)("DATAUSAGE"))
                tbArpu.Text = NVL(dt.Rows(0)("ARPU"))
                tbDeakCezaTutari.Text = NVL(dt.Rows(0)("DEAKTCEZA"))
                tbRMoInvoiceTL.Text = NVL(dt.Rows(0)("ROAMMOINVFEE"))
                tbRMtVoiceTL.Text = NVL(dt.Rows(0)("ROAMMTINVFEE"))
                tbRMoSmsTL.Text = NVL(dt.Rows(0)("ROAMMOSMSFEE"))
                tbRGprsTL.Text = NVL(dt.Rows(0)("ROAMGPRSFEE"))
                tbRMtSmsTL.Text = NVL(dt.Rows(0)("ROAMMTSMSFEE"))
                tbRMoInvoiceDkAdMb.Text = NVL(dt.Rows(0)("ROAMMOINVAMNT"))
                tbRMtVoiceDkAdMb.Text = NVL(dt.Rows(0)("ROAMMTINVAMNT"))
                tbRMoSmsDkAdMb.Text = NVL(dt.Rows(0)("ROAMMOSMSAMNT"))
                tbRGprsDkAdMb.Text = NVL(dt.Rows(0)("ROAMGPRSAMNT"))
                tbTaeh.Text = NVL(dt.Rows(0)("TAEHTUTARI"))
                tbRMtSmsDkAdMb.Text = NVL(dt.Rows(0)("ROAMMTSMSAMNT"))
                tbTenureHat.Text = NVL(dt.Rows(0)("TENURE"))
                tbMvpncode.Text = NVL(dt.Rows(0)("MVPN"))
                tbActDate.Text = NVL(dt.Rows(0)("COACTIVATED"))
                tblR2C1.InnerHtml = "<a href=""#"" onclick=""openPromoList('RetentionToolPromotionInfo.aspx?ASSIGNTYPE=" & rbTeklifVermeTipi.SelectedValue & "&LEVEL=HAT&CUSTOMER=" & p_msisdn & "&CUSTOMERID=" & NVL(dt.Rows(0)("CUSTOMERID")) & "&STATUS=ACTIVE" & "')"" >Aktif İndirimler</a>"
                tblR2C8.InnerHtml = "<a href=""#"" onclick=""openPromoList('RetentionToolPromotionInfo.aspx?ASSIGNTYPE=" & rbTeklifVermeTipi.SelectedValue & "&LEVEL=HAT&CUSTOMER=" & p_msisdn & "&CUSTOMERID=" & NVL(dt.Rows(0)("CUSTOMERID")) & "&STATUS=DEACTIVE" & "')"" >Deaktif İndirimler</a>"
                tblR4C1.InnerHtml = "<a href=""#"" onclick=""openTariffHist('RetentionToolTariffInfo.aspx?CUSTOMER=" & p_msisdn & "&COID=" & NVL(dt.Rows(0)("COID")) & "')"" >Tarife Geçmişi</a>"

                If rbTeklifVermeTipi.SelectedValue = 2 Or rbTeklifVermeTipi.SelectedValue = 4 Then
                    tblR10C5.Attributes("class") = "solbaslik"
                    tblR10C5.InnerHtml = "<a href=""#"" onclick=""openCustomerDetails('CustomerDetails.aspx?CustCode=" & NVL(dt.Rows(0)("CUSTCODE")) & "')"" >Hat Detayı</a>"
                End If

            Else
                Session("RTAO_MSISDN" & p_msisdn) = Nothing
                Session("RTAO_MSISDN_BP" & p_msisdn) = Nothing
            End If



            If Not (Session("RTAO_MSISDN_BP" & p_msisdn) Is Nothing) Then
                dt = Session("RTAO_MSISDN_BP" & p_msisdn)
            Else
                dt = getBindingPackages(p_msisdn, Session("user"))
            End If

            If dt.Rows.Count > 0 Then
                Session("RTAO_MSISDN_BP" & p_msisdn) = dt
                dgHat.Visible = True
                dgHat.CurrentPageIndex = 0
                dgHat.DataSource = dt
                dgHat.DataBind()
                lblTaahPaket.Text = "Taahhütlü Paketler"

                Dim tblR14 As HtmlTableRow = New HtmlTableRow
                Dim tblR14C1 As HtmlTableCell = New HtmlTableCell
                tblR14C1.Attributes("class") = "input"
                tblR14C1.Attributes("colSpan") = "7"
                tblR14C1.Attributes("style") = "PADDING-RIGHT: 5px;PADDING-LEFT: 5px;"
                dgHat.Attributes.Add("runat", "server")
                dgHat.Style.Add("Width", "100%")
                dgHat.Style.Add("CellPadding", "3")
                dgHat.Style.Add("HorizontalAlign", "Left")
                dgHat.Style.Add("BorderStyle", "None")
                dgHat.Style.Add("BorderWidth", "1px")
                dgHat.Style.Add("BorderColor", "#CCCCCC")
                dgHat.BackColor = Drawing.Color.White
                dgHat.AllowPaging = False
                dgHat.FooterStyle.CopyFrom(dgFaturanlaKazan.FooterStyle)
                dgHat.SelectedItemStyle.CopyFrom(dgFaturanlaKazan.SelectedItemStyle)
                dgHat.ItemStyle.CopyFrom(dgFaturanlaKazan.ItemStyle)
                dgHat.HeaderStyle.CopyFrom(dgFaturanlaKazan.HeaderStyle)
                dgHat.PagerStyle.CopyFrom(dgFaturanlaKazan.PagerStyle)
                dgHat.ItemStyle.Font.Bold = False
                dgHat.ItemStyle.ForeColor = Drawing.Color.White
                tblR14C1.Controls.Add(dgHat)
                tblR14.Controls.Add(tblR14C1)
                tblHat.Controls.Add(tblR14)

                Dim tblR15 As HtmlTableRow = New HtmlTableRow
                Dim tblR15C1 As HtmlTableCell = New HtmlTableCell
                tblR15C1.Attributes("colSpan") = "7"
                tblR15.Controls.Add(tblR15C1)
                tblHat.Controls.Add(tblR15)

            Else
                dgHat.Visible = False
                lblTaahPaket.Text = "Taahhütlü Paket bulunmamaktadır!."
            End If

            Return tblHat

        End Function


        Private Sub Contract_Deact_Ceza_Hesapla(ByVal sender As System.Object, ByVal e As System.EventArgs)

            Dim p_msisdn As String = CType(sender, Button).ID.Substring(14, 10)
            Dim result As String() = getContractDeactPanaltyAmount(p_msisdn, p_user, Session("user"))
            Dim btnID As String = "btnCezaHesapla" & p_msisdn
            Message = "document.getElementById('" & btnID & "').focus();"
            Dim dt As DataTable = Session("RTAO_MSISDN" & p_msisdn)
            dt.Rows(0)("DEAKTCEZA") = result(0).ToString
            Dim myDiv As HtmlControl = Page.FindControl("myDiv")
            myDiv.Controls.Clear()

            Try
                '-----------------------
                Dim totalAmount As Double
                Dim dtRetentionFee As DataTable
                dtRetentionFee = persistent.GhhServicesFeeList.GetFeeList("c", "", tbCustcode.Text, "ALLSERVICES", Session("user"), totalAmount)
                If dtRetentionFee.Rows.Count > 0 Then
                    dgRetentionCeza.DataSource = dtRetentionFee
                    dgRetentionCeza.DataBind()
                    tbDeaktivasyonCezaTutari.Text = totalAmount.ToString()
                    divRetentionCeza.Visible = True
                Else
                    divRetentionCeza.Visible = False
                End If
            Catch e2 As Exception
                dgRetentionCeza.Visible = False
            End Try

            renderContractBasedInfo()

        End Sub




        Private Shared Function NVL(ByVal inputValue As Object) As String
            If IsDBNull(inputValue) Then
                Return String.Empty
            Else
                Return CStr(inputValue)
            End If
        End Function


        Private Sub initalizeAreas()

            tbCustcode.Text = ""
            tbSrNumber.Text = ""
            tbMSISDN.Text = ""
            lblAdSoyadUnvan.Enabled = False
            tbAdSoyadUnvan.Text = ""
            tbAdSoyadUnvan.Enabled = False
            lbCustomerDetail.Text = "Müşteri Detayı"
            lbCustomerDetail.Enabled = False
            cbBayiHatIptal.Checked = False
            cbBayiHatIptal.Enabled = False
            ddEvrakDurumu.Enabled = False
            lblEvrakDurumu.Enabled = False
            ddEvrakDurumu.SelectedValue = -1
            ddlRetNedeni.Enabled = False
            tbUserNotes1.Text = ""
            ddlRetNedeni.SelectedValue = -1
            lblRetNedeni.Enabled = False
            ddlAramaTipi.Enabled = False
            ddlAramaTipi.SelectedValue = 0
            lblAramaTipi.Enabled = False
            lbMsisdnList.Items.Clear()
            pnlRetGecmis.Visible = False
            pnlUserNotes.Visible = False
            pnlHatBazli.Visible = False
            pnlSirketBazli.Visible = False
            tbUserNotes1.Visible = False
            lblUserNotes.Visible = False
            lblMsisdnList.Text = ""
            lblMsisdnList.Visible = False
            lbMsisdnList.Visible = False
            lbtnMsisdnList.Text = "Numara Seç"
            lbtnMsisdnList.Enabled = False
            initializeSessionVariables()
            pnlLF.Visible = False
            pnlPBC.Visible = False
            pnlPBCIslemTuru.Visible = False
            'rbPBCIslemTuru.SelectedValue = 0
            rbPBCIslemTuru.SelectedValue = 2 'Hızlı BC
            rbPBCIslemTuru.Enabled = False
            pnlIslemYapilacakHatlar.Visible = False
            lblAktifIndirimler.Text = "Aktif İndirimler"
            lblDeaktifIndirimler.Text = "Deaktif İndirimler"
            Dim HREFHatBazliSelection As HtmlControl = Page.FindControl("HREFHatBazliSelection")
            HREFHatBazliSelection.Attributes("style") = "DISPLAY: none"
            rbHatBazliBind()
            tbDeaktivasyonCezaTutari.Text = ""
            pnlTeklif.Visible = False
            pnlTeklifVermeme.Visible = False
            cbTeklifVermeme.Checked = False
            Dim tdTeklifler As HtmlTableCell = Page.FindControl("tdTeklifler")
            tdTeklifler.Attributes("style") = "PADDING-LEFT: 5px;PADDING-RIGHT: 5px"
            lblPBCType3.Visible = False
            lblPBCType3.Text = ""

        End Sub

        Private Sub rbHatBazliBind()

            rbHatBazli.Items.Clear()

            rbHatBazli.Items.Add(New ListItem("Tümü", "0"))
            If rbTeklifVermeTipi.SelectedValue = 4 Then
                rbHatBazli.Items.Add(New ListItem("İşlem için seçilmişleri", "1"))
            End If
            rbHatBazli.Items.Add(New ListItem("Tümünden seçilenleri", "2"))
            If rbTeklifVermeTipi.SelectedValue = 4 Then
                rbHatBazli.Items.Add(New ListItem("İşlem için seçilenlerden seçilenleri", "4"))
            End If
            rbHatBazli.Items.Add(New ListItem("Girilen Numarayı", "3"))

            lbMsisdnInfoList.Visible = False
            tbHatMsisdn.Visible = False
            tbHatMsisdn.Text = ""

        End Sub

        Private Function inputControl(ByVal p_custcode As String, ByVal p_msisdn As String, ByVal p_teklif_verme_tipi As Integer) As Boolean


            If p_teklif_verme_tipi = 1 Then

                If Trim(p_custcode) = "" And Trim(p_msisdn) = "" Then
                    Message = "alert('Lütfen Custcode veya MSISDN giriniz!');"
                    Return False
                ElseIf Trim(p_custcode) <> "" And Trim(p_msisdn) <> "" Then
                    Message = "alert('Lütfen Custcode veya MSISDNden sadece birini giriniz!');"
                    Return False
                ElseIf Trim(p_msisdn) <> "" And Not IsNumeric(Trim(p_msisdn)) Then
                    Message = "alert('MSISDN numerik bir değer olmalıdır!');"
                    Return False
                ElseIf Trim(p_msisdn) <> "" And Trim(p_msisdn).Length <> 10 Then
                    Message = "alert('MSISDN 10 hane olmalıdır!');"
                    Return False
                End If

            ElseIf p_teklif_verme_tipi = 3 Then

                tbCustcode.Text = ""
                If Trim(p_msisdn) = "" Then
                    Message = "alert('Lütfen MSISDN giriniz!');"
                    Return False
                ElseIf Trim(p_msisdn) <> "" And Not IsNumeric(Trim(p_msisdn)) Then
                    Message = "alert('MSISDN numerik bir değer olmalıdır!');"
                    Return False
                ElseIf Trim(p_msisdn) <> "" And Trim(p_msisdn).Length <> 10 Then
                    Message = "alert('MSISDN 10 hane olmalıdır!');"
                    Return False
                End If

            End If

            Return True

        End Function


        Private Sub btnGoruntule_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGoruntule.Click
            Dim p_linecancel As Integer = -1
            Dim p_infodealer As String = "NULL"
            Dim p_srnumber As String = ""
            Dim p_custcode As String = "NULL"
            Dim p_msisdn As String = "NULL"
            Dim p_retention_id As Integer = -1

            Dim p_calltype As String = "NULL"
            Dim p_errorCode As String = "0"
            Dim p_errorMessage As String = "NULL"
            Dim p_errorDetail As String = "NULL"
            Dim p_errorType As String = "NULL"
            Dim p_tid As String = "NULL"
            Dim p_transactiondate As String = DateTime.Now.ToString("MM'/'dd'/'yyyy HH:mm:ss")

            Dim p_control As String = "-1"
            ' tbSrNumber.Text <> p_control Or 

            'Dim sdafa1 As String() = setTransactionLog(p_tid, p_srnumber, p_custcode, p_msisdn, p_linecancel, p_infodealer, p_calltype, p_transactiondate, p_errorCode, p_errorMessage, p_errorDetail, p_errorType)
        

            If Trim(tbSrNumber.Text) <> "-1" Then
                If Trim(tbSrNumber.Text) <> "" Then
                    p_srnumber = Trim(tbSrNumber.Text)

                    Dim SRNumber = p_srnumber
                    Dim UserId = p_user
                    Dim TransactionDate = p_transactiondate



                    Dim requestXML As String = String.Format _
                    ( _
                        GetFileContent(Server.MapPath("\ccapps\web\Templates\QueryRetention.XML")), _
                        SRNumber, _
                        UserId, _
                        TransactionDate _
                    )

                    Dim data() As Byte = _
                    System.Text.Encoding.Convert _
                    ( _
                        System.Text.Encoding.GetEncoding("windows-1254"), _
                        System.Text.Encoding.GetEncoding("iso-8859-9"), _
                        System.Text.Encoding.GetEncoding("windows-1254").GetBytes(requestXML) _
                    )

                    Dim retentionURL As String = persistent.myDBConn.ORAScalar("select parameter_value from EU_BILL.WA_GLOBAL_CONFIGURATION where wa_name='RETENTION' and parameter_name='WebServiceURL'")
                    Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(retentionURL)
                    request.Method = "POST"
                    request.ContentType = "content=""text/xml;charset=iso-8859-9"""
                    request.ContentLength = data.Length
                    Dim strXML
                    Dim reader As IO.StreamReader
                    Try
                        Dim streamWriter As New System.IO.StreamWriter(request.GetRequestStream(), System.Text.Encoding.GetEncoding("iso-8859-9"))
                        streamWriter.Write(System.Text.Encoding.GetEncoding("iso-8859-9").GetString(data))
                        streamWriter.Close()


                        Dim response As System.IO.Stream = request.GetResponse().GetResponseStream()
                        Dim responseReader As New IO.StreamReader(response, System.Text.Encoding.UTF8)
                        Dim responseXML As String = responseReader.ReadToEnd()

                        Dim ds As New DataSet
                        Dim sr As New System.IO.StringReader(responseXML)
                        Dim XmlDoc As New System.Xml.XmlDocument
                        Dim xmlNodeReader As New System.Xml.XmlNodeReader(XmlDoc)

                        XmlDoc.Load(sr)
                        ds.ReadXml(xmlNodeReader)
                        xmlNodeReader.Close()
                        sr.Close()
                        responseReader.Close()
                        response.Close()
                        streamWriter.Close()



                        For Each row As DataRow In ds.Tables("ResponseHeader").Rows

                            p_tid = row("Tid")

                        Next


                        For Each row As DataRow In ds.Tables("ResponseBody").Rows

                            If row("InfoDealerRequestor") = "Y" Then

                                p_infodealer = "Y"
                                '    cbBayiHatIptal.Checked = True
                            Else
                                p_infodealer = "N"
                            End If

                            If row("LineCancellationReason") <> "" Then
                                p_linecancel = CInt(row("LineCancellationReason"))

                                'ddlRetNedeni.Items.Clear()
                                'ddlRetNedeni.Items.Add(New ListItem(l_rn, "0"))
                            End If

                            If row("MSISDN") <> "" Then
                                If ((rbTeklifVermeTipi.SelectedValue = 1) Or (rbTeklifVermeTipi.SelectedValue = 3)) Then
                                    tbMSISDN.Text = row("MSISDN")
                                    p_msisdn = row("MSISDN")
                                End If
                            End If


                            If row("CallType") <> "" Then
                                p_calltype = row("CallType")

                                'ddlAramaTipi.Items.Clear()
                                'ddlAramaTipi.Items.Add(New ListItem(l_at, "0"))
                            End If


                            If row("CustCode") <> "" Then
                                If ((rbTeklifVermeTipi.SelectedValue = 2) Or (rbTeklifVermeTipi.SelectedValue = 4)) Then
                                    tbCustcode.Text = row("CustCode")
                                    p_custcode = row("CustCode")
                                End If
                            End If
                        Next


                        'Catch ex As System.Web.Services.Protocols.SoapException
                        '    Console.WriteLine("message:>" & ex.Message)
                        '    Console.WriteLine("detail:>" & ex.Detail.InnerXml)
                        'Catch ex1 As Exception
                        '    Dim reader As IO.StreamReader = New IO.StreamReader(ex1.InnerException.GetResponseStream())
                        '    Dim strXML = reader.ReadToEnd()

                    Catch ex2 As System.Net.WebException
                        'tbSrNumber.Text = ""
                        tbSrNumber.Text = "-1"
                        'tbSrNumber.DataBind()
                        If ex2.Status.ToString.Trim = "ConnectFailure" Then
                            Message = "alert('Sr Id bilgisi alırken bağlantı hatası oluştu!');"
                            Return
                        Else
                            Try
                                reader = New IO.StreamReader(ex2.Response.GetResponseStream())
                                strXML = reader.ReadToEnd()

                            Catch
                                Message = "alert('Sr Id bilgisi alırken bağlantı hatası oluştu!');"
                                Return
                            End Try
                        End If
                        If strXML <> "" Then

                            Dim ds1 As New DataSet
                            Dim sr1 As New System.IO.StringReader(strXML)
                            Dim XmlDoc1 As New System.Xml.XmlDocument
                            Dim xmlNodeReader1 As New System.Xml.XmlNodeReader(XmlDoc1)

                            XmlDoc1.Load(sr1)
                            ds1.ReadXml(xmlNodeReader1)
                            xmlNodeReader1.Close()
                            sr1.Close()
                            reader.Close()



                            For Each row1 As DataRow In ds1.Tables("mwFault").Rows
                                If row1("errorCode") <> "" Then
                                    p_errorCode = row1("errorCode")
                                End If
                                If row1("errorMessage") <> "" Then
                                    p_errorMessage = row1("errorMessage")
                                End If
                                If row1("errorDetail") <> "" Then
                                    p_errorDetail = row1("errorDetail")
                                End If
                                If row1("errorType") <> "" Then
                                    p_errorType = row1("errorType")
                                End If
                                p_tid = row1("tid")
                            Next
                        End If
                        setTransactionLog(p_tid, p_srnumber, p_retention_id, p_custcode, p_msisdn, p_linecancel, p_infodealer, p_calltype, p_user, p_errorCode, p_errorMessage, p_errorDetail, p_errorType)


                        If p_errorCode <> "0" Then
                            Message = "alert('Hatalı SR Girdiniz');"
                            'Message = "alert(""" & p_errorMessage & """)"
                            Return
                        End If
                    End Try

                End If
            End If
            'ddlRetNedeni.Items.Clear()
            'ddlRetNedeni.Items.Add(New ListItem(l_rn, "0"))


            'ElseIf rbTeklifVermeTipi.SelectedValue = 2 Then 'Bireysel Teklif
            'ElseIf rbTeklifVermeTipi.SelectedValue = 2 Then 'Sirkete Teklif
            'ElseIf rbTeklifVermeTipi.SelectedValue = 3 Then 'Sirketin Bir(1) Hattyna Teklif
            'ElseIf rbTeklifVermeTipi.SelectedValue = 4 Then 'Sirketin Birden Fazla Hattyna Teklif

            'If Trim(tbCustcode.Text) <> "" And Not IsNumeric(tbCustcode.Text.Trim().Substring(0, 1)) Then

            '    Message = "alert('Custcode uygun formattta değildir!');"
            '    Return

            'End If

            If inputControl(tbCustcode.Text, tbMSISDN.Text, rbTeklifVermeTipi.SelectedValue) = False Then
                Return
            End If

            If Trim(tbCustcode.Text) = "" Then

                p_custcode = "0"
            Else
                p_custcode = Trim(tbCustcode.Text)

            End If


            If Trim(tbMSISDN.Text) = "" Then

                p_msisdn = "0"
            Else

                p_msisdn = Trim(tbMSISDN.Text)

            End If

            Dim dt As DataTable = getCustomerInfo(p_custcode, p_msisdn, rbTeklifVermeTipi.SelectedValue, p_user, Session("user"))

            If dt.Rows.Count > 0 Then

                initalizeAreas()

                Session("rtao_srnumber") = p_srnumber
                If dt.Rows(0)("RESULT") <> "OK" Then
                    Message = "alert(""" & dt.Rows(0)("RESULT") & """)"
                    Return
                End If
                If p_infodealer = "Y" Then
                    cbBayiHatIptal.Checked = True
                    ddEvrakDurumu.SelectedValue = 1
                    cbBayiHatIptal.Enabled = False
                    ddEvrakDurumu.Enabled = False
                    lblEvrakDurumu.Enabled = False
                ElseIf p_infodealer = "N" Then
                    cbBayiHatIptal.Checked = False
                    cbBayiHatIptal.Enabled = True
                    ddEvrakDurumu.Enabled = True
                    lblEvrakDurumu.Enabled = True
                    ddEvrakDurumu.SelectedValue = 0
                Else
                    If dt.Rows(0)("BAYITALEBI") = 1 Then
                        cbBayiHatIptal.Checked = True
                        ddEvrakDurumu.SelectedValue = 1
                        cbBayiHatIptal.Enabled = False
                        ddEvrakDurumu.Enabled = False
                        lblEvrakDurumu.Enabled = False
                    Else
                        cbBayiHatIptal.Checked = False
                        cbBayiHatIptal.Enabled = True
                        ddEvrakDurumu.Enabled = True
                        lblEvrakDurumu.Enabled = True
                        ddEvrakDurumu.SelectedValue = 0

                    End If
                End If


                tbAdSoyadUnvan.Text = dt.Rows(0)("ADSOYADUNVAN")
                lblAdSoyadUnvan.Enabled = True
                tbAdSoyadUnvan.Enabled = True
                'Buraya method yazılacak
                If (rbTeklifVermeTipi.SelectedValue = 2 Or rbTeklifVermeTipi.SelectedValue = 4) Then
                    Session("rtao_custcode") = getHighLevelCustcode(dt.Rows(0)("CUSTCODE").ToString())
                Else
                    Session("rtao_custcode") = dt.Rows(0)("CUSTCODE")
                End If



                lbCustomerDetail.Text = "<b><a href=""#"" onclick=""openCustomerDetails('CustomerDetails.aspx?CustCode=" & Session("rtao_custcode") & "')"" >Müşteri Detayı</a></b>"
                Session("rtao_customerid") = dt.Rows(0)("CUSTOMERID")
                tbCustcode.Text = Session("rtao_custcode")
                tbSrNumber.Text = Session("rtao_srnumber")
                If dt.Rows(0)("MSISDN") = "0" Then
                    Session("rtao_msisdn") = ""
                Else
                    Session("rtao_msisdn") = dt.Rows(0)("MSISDN")
                    Session("rtao_msisdn_status") = dt.Rows(0)("MSISDNSTATUS")
                End If
                Session("rtao_retcustomertypeid") = dt.Rows(0)("RETCUSTOMERTYPEID")
                Session("rtao_customer_type") = dt.Rows(0)("CUSTOMER_TYPE")
                Session("rtao_fpm_payer_coid") = dt.Rows(0)("FPMPAYERCOID")
                tbMSISDN.Text = Session("rtao_msisdn")

                'If dt.Rows(0)("BAYITALEBI") = 1 Then
                '    cbBayiHatIptal.Checked = True
                '    ddEvrakDurumu.SelectedValue = 1
                '    cbBayiHatIptal.Enabled = False
                '    ddEvrakDurumu.Enabled = False
                '    lblEvrakDurumu.Enabled = False
                'Else
                '    cbBayiHatIptal.Checked = False
                '    cbBayiHatIptal.Enabled = True
                '    ddEvrakDurumu.Enabled = True
                '    lblEvrakDurumu.Enabled = True
                '    ddEvrakDurumu.SelectedValue = 0

                'End If

                ddlRetNedeni.Enabled = True
                'ddlRetNedeni.SelectedValue = 0
                ddlRetNedeniBind(Session("rtao_retcustomertypeid"))
                If p_linecancel <> -1 Then

                    'ddlRetNedeni.Items.Clear()
                    'ddlRetNedeni.Items.Add(New ListItem(retreason, "0"))
                    'ddlRetNedeni.SelectedValue = 0
                    'If ddlRetNedeni.Items.Count <= p_linecancel Then
                    '    Message = "alert('Retention Nedeni Sistemde kayıtlı değil!')"
                    '    ddlRetNedeni.SelectedIndex = -1
                    'Else

                    '    For value As Integer = 0 To ddlRetNedeni.Items.Count

                    '        ddlRetNedeni.SelectedIndex = value - 1

                    '        If ddlRetNedeni.SelectedIndex = p_linecancel Then
                    '            ddlRetNedeni.SelectedIndex = value - 1
                    '            Exit For
                    '        End If
                    '    Next
                    'End If
                    If ddlRetNedeni.Items.FindByValue(p_linecancel).Text <> "" Then
                        ddlRetNedeni.SelectedIndex = ddlRetNedeni.Items.IndexOf(ddlRetNedeni.Items.FindByValue(p_linecancel))
                    Else
                        Message = "alert('Retention Nedeni Sistemde kayıtlı değil!')"
                        ddlRetNedeni.SelectedIndex = -1
                    End If

                End If
                ddlAramaTipi.Enabled = True
                lblRetNedeni.Enabled = True

                If p_calltype.ToUpper.Trim = "INBOUND" Then
                    ddlAramaTipi.SelectedIndex = 1
                ElseIf p_calltype.ToUpper.Trim = "OUTBOUND" Then
                    ddlAramaTipi.SelectedIndex = 2
                Else
                    ddlAramaTipi.SelectedValue = 0
                End If
                ' ddlAramaTipi.SelectedValue = 0
                lblAramaTipi.Enabled = True

                lbCustomerDetail.Enabled = True

                pnlRetGecmis.Visible = True


                If Session("rtao_msisdn") = "" Then
                    dgRetentionHistBind(Session("rtao_customerid"), "-1")
                Else
                    dgRetentionHistBind(Session("rtao_customerid"), Session("rtao_msisdn"))
                End If



                pnlHatBazli.Visible = True


                If rbTeklifVermeTipi.SelectedValue = 1 Or rbTeklifVermeTipi.SelectedValue = 3 Then

                    Dim dtMsisdn As DataTable = New DataTable
                    dtMsisdn.Columns.Add(New DataColumn("MSISDN", GetType(String)))
                    dtMsisdn.Columns.Add(New DataColumn("STATUS", GetType(String)))
                    Dim dtRow As DataRow = dtMsisdn.NewRow()
                    dtRow.Item("MSISDN") = Session("rtao_msisdn")
                    dtRow.Item("STATUS") = Session("rtao_msisdn") & " (" & Session("rtao_msisdn_status") & ") "
                    dtMsisdn.Rows.Add(dtRow)
                    Session("RTAO_Selected_MSISDN_INFO") = dtMsisdn
                    Session("RTML_Selected_MSISDN") = Session("RTAO_Selected_MSISDN_INFO")
                    dgIslemYapilacakHatlarBind()

                End If
                Dim newdt As DataTable
                newdt = getMsisdnList(Session("rtao_custcode"), 0, Session("user"))
                aktif_hat = newdt.Rows.Count

                If rbTeklifVermeTipi.SelectedValue <> 1 Then
                    pnlSirketBazli.Visible = True
                    CustomerBasedInfoBind(Session("rtao_customerid"))
                    lblAktifIndirimler.Text = "<a href=""#"" onclick=""openPromoList('RetentionToolPromotionInfo.aspx?ASSIGNTYPE=" & rbTeklifVermeTipi.SelectedValue & "&LEVEL=SIRKET&CUSTOMER=" & tbAdSoyadUnvan.Text & "&CUSTOMERID=" & Session("rtao_customerid") & "&STATUS=ACTIVE" & "')"" >Aktif İndirimler</a>"
                    lblDeaktifIndirimler.Text = "<a href=""#"" onclick=""openPromoList('RetentionToolPromotionInfo.aspx?ASSIGNTYPE=" & rbTeklifVermeTipi.SelectedValue & "&LEVEL=SIRKET&CUSTOMER=" & tbAdSoyadUnvan.Text & "&CUSTOMERID=" & Session("rtao_customerid") & "&STATUS=DEACTIVE" & "')"" >Deaktif İndirimler</a>"

                End If

                If rbTeklifVermeTipi.SelectedValue = 2 Then
                    pnlTeklif.Visible = True
                    Dim dtSirket As DataTable = getMsisdnList(Session("rtao_custcode"), Session("rtao_fpm_payer_coid"), Session("user"))
                    Session("RTML_Selected_MSISDN") = dtSirket
                    dgIslemYapilacakHatlarBind()
                End If


                If rbTeklifVermeTipi.SelectedValue = 4 Then
                    lblMsisdnList.Enabled = True
                    lbtnMsisdnList.Enabled = True
                    lbMsisdnList.Enabled = True
                    lbMsisdnListBind(Session("rtao_custcode"))
                    Session("RTML_Selected_MSISDN") = Nothing

                End If

                rbHatBazliBind()

            Else

                Message = "alert('Abone bulunamadı!')"
                Return

            End If

            Dim tblSirketBazliBilgiler As HtmlTable = Page.FindControl("tblSirketBazliBilgiler")
            tblSirketBazliBilgiler.Attributes("style") = "DISPLAY: none"

            Dim tblRetentionHistory As HtmlTable = Page.FindControl("tblRetentionHistory")
            tblRetentionHistory.Attributes("style") = "DISPLAY: none"

            Dim TRHatBazliBilgiler As HtmlTableRow = Page.FindControl("TRHatBazliBilgiler")
            TRHatBazliBilgiler.Attributes("style") = "DISPLAY: none"

            Dim myDiv As HtmlControl = Page.FindControl("myDiv")
            myDiv.Controls.Clear()
            renderContractBasedInfo()



        End Sub

        Private Sub dgIslemYapilacakHatlarBind()

            Dim dt As DataTable = Session("RTML_Selected_MSISDN")

            If dt.Rows.Count > 0 Then

                If rbTeklifVermeTipi.SelectedValue = 1 Or rbTeklifVermeTipi.SelectedValue = 3 Then
                    lblIslemYapilacakHat.Text = "İşlem Yapılacak Hat"
                ElseIf rbTeklifVermeTipi.SelectedValue = 4 Then
                    lblIslemYapilacakHat.Text = "İşlem Yapılacak Hatlar"
                Else
                    lblIslemYapilacakHat.Text = "Şirket Hatları"
                End If


                'If rbTeklifVermeTipi.SelectedValue = 4 Or rbTeklifVermeTipi.SelectedValue = 2 Then
                If rbTeklifVermeTipi.SelectedValue <> 1 Then
                    dgIslemYapilacakHatlar.Columns(5).Visible = True
                    Me.cbHepsiniSec.Visible = True

                Else
                    dgIslemYapilacakHatlar.Columns(5).Visible = False
                    Me.cbHepsiniSec.Visible = False

                End If


                'Özet Kullanım Raporu
                If rbTeklifVermeTipi.SelectedValue = 1 Then
                    dgIslemYapilacakHatlar.Columns(6).Visible = True
                Else
                    dgIslemYapilacakHatlar.Columns(6).Visible = False
                End If

                pnlIslemYapilacakHatlar.Visible = True
                dgIslemYapilacakHatlar.Visible = True
                dgIslemYapilacakHatlar.DataSource = dt
                dgIslemYapilacakHatlar.DataBind()
                pnlTeklif.Visible = True
                dgTekliflerBind(ddEvrakDurumu.SelectedValue)
                ddlTeklifVermemeBind()

            Else
                pnlIslemYapilacakHatlar.Visible = False
                dgIslemYapilacakHatlar.Visible = False
                pnlTeklif.Visible = False
            End If

            If dt.Rows.Count > 0 Then
                cbHepsiniSec.Checked = True
                For Each dgi As DataGridItem In dgIslemYapilacakHatlar.Items

                    Dim tb As TextBox = CType(dgi.FindControl("tbLFUygunlugu"), TextBox)

                    Dim result As String() = checkLF(dgi.Cells(0).Text, Session("user"))

                    tb.Text = result(0)

                    dgi.Cells(4).Text = "<a href=""#"" onclick=""openContractHist('RetentionToolContractHistory.aspx?MSISDN=" & dgi.Cells(0).Text & "')"" >Statü Geçmişi</a>"

                    dgi.Cells(6).Text = "<a href=""#"" onclick=""openContractHist('UsageSummaryReport.aspx?MSISDN=" & dgi.Cells(0).Text & "')"" >Özet Kullanım<br/>Raporu</a>"

                    Dim tbPO As TextBox = CType(dgi.FindControl("tbPortOutRequest"), TextBox)

                    Dim resultPO As String() = checkMnpPortOut(dgi.Cells(0).Text, Session("user"))

                    tbPO.Text = resultPO(0)


                    If rbTeklifVermeTipi.SelectedValue = 3 Then
                        Dim cb As CheckBox = CType(dgi.FindControl("cbHatIptal"), CheckBox)
                        cb.Checked = True
                    End If

                    If rbTeklifVermeTipi.SelectedValue = 4 Or rbTeklifVermeTipi.SelectedValue = 2 Then
                        Dim cb As CheckBox = CType(dgi.FindControl("cbHatIptal"), CheckBox)
                        Dim resultHI As String() = getDealerLineCancelRequest(dgi.Cells(0).Text, Session("user"))
                        If resultHI(0) = "1" Then
                            cb.Checked = True
                            cb.Enabled = False
                        Else
                            cb.Checked = cbBayiHatIptal.Checked
                        End If
                    Else

                        Dim resultHI As String() = getDealerLineCancelRequest(dgi.Cells(0).Text, Session("user"))
                        If resultHI(0) = "0" Then
                            cbBayiHatIptal.Checked = False
                            cbBayiHatIptal.Enabled = True
                        Else
                            cbBayiHatIptal.Checked = True
                            cbBayiHatIptal.Enabled = False
                            ddEvrakDurumu.SelectedValue = "1"
                        End If

                    End If

                    If rbTeklifVermeTipi.SelectedValue <> 1 Then

                        Dim cb As CheckBox = CType(dgi.FindControl("cbHatIptal"), CheckBox)
                        cb.Checked = True

                    End If


                Next

            End If

        End Sub

        'Private Sub lbCustomerDetail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbCustomerDetail.Click
        '    RegisterScript("openCustomerDetails('CustomerDetails.aspx?CustCode=" & Session("rtao_custcode") & "')")
        'End Sub


        'Private Sub lblAktifIndirimler_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblAktifIndirimler.Click
        '    RegisterScript("openPromoList('RetentionToolPromotionInfo.aspx?MSISDN=" & tbAdSoyadUnvan.Text & "&CUSTOMERID=" & Session("rtao_customerid") & "')")
        'End Sub

        'Private Sub lbtnMsisdnList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbtnMsisdnList.Click

        '    Dim p_custcode As String = Session("rtao_custcode")
        '    RegisterScript("openMsisdnList('RetentionToolMsisdnList.aspx?CUSTCODE=" & p_custcode & "')")
        'End Sub

        Protected Sub refreshButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles refreshbutton.ServerClick
            lblMsisdnList.Visible = True
            lbMsisdnList.Visible = True

            lbMsisdnList.Items.Clear()
            Dim dt As DataTable = Session("RTML_Selected_MSISDN")
            If dt.Rows.Count > 0 Then
                lbMsisdnList.Enabled = True
                For Each dr As DataRow In dt.Rows
                    lbMsisdnList.Items.Add(New ListItem(dr("STATUS").ToString(), dr("MSISDN").ToString()))
                Next
                lblMsisdnList.Text = ""
                lblMsisdnList.Visible = True
                lbMsisdnList.Visible = True

            Else
                lbMsisdnList.Enabled = False
                lbtnMsisdnList.Enabled = True
                lblMsisdnList.Text = "MSISDN Seciniz!."
                lblMsisdnList.Visible = True
                lbMsisdnList.Visible = False
                pnlUserNotes.Visible = False
                tbUserNotes1.Visible = False
                lblUserNotes.Visible = False
                tbUserNotes1.Text = ""
            End If

            dgIslemYapilacakHatlarBind()
            tbDeaktivasyonCezaTutari.Text = ""

        End Sub


        Private Sub rbHatBazli_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbHatBazli.SelectedIndexChanged

            'lbMsisdnInfoListBind(Session("rtao_customerid"))

            Select Case rbHatBazli.SelectedValue

                Case "0" 'Tümü
                    lbMsisdnInfoList.Visible = False
                    tbHatMsisdn.Visible = False
                    tbHatMsisdn.Text = ""
                    lbMsisdnInfoListBind(Session("rtao_custcode"))
                Case "1" 'İşlem için seçilenler
                    lbMsisdnInfoList.Visible = False
                    tbHatMsisdn.Visible = False
                    tbHatMsisdn.Text = ""
                Case "2" 'Seçim Yapılanlar
                    lbMsisdnInfoList.Visible = True
                    tbHatMsisdn.Visible = False
                    tbHatMsisdn.Text = ""
                    lbMsisdnInfoListBind(Session("rtao_custcode"))
                Case "3" 'Msisdn
                    lbMsisdnInfoList.Visible = False
                    tbHatMsisdn.Visible = True
                    tbHatMsisdn.Text = ""
                    lbMsisdnInfoListBind(Session("rtao_custcode"))
                Case "4" 'İşlem için seçilenlerden seçim yap

                    tbHatMsisdn.Visible = False
                    tbHatMsisdn.Text = ""

                    lbMsisdnInfoList.Items.Clear()

                    If Not (Session("RTML_Selected_MSISDN") Is Nothing) Then

                        lbMsisdnInfoList.Visible = True

                        Dim dt As DataTable = (Session("RTML_Selected_MSISDN"))
                        If dt.Rows.Count > 0 Then

                            For Each dr As DataRow In dt.Rows
                                lbMsisdnInfoList.Items.Add(New ListItem(dr("STATUS").ToString(), dr("MSISDN").ToString()))
                            Next
                        Else
                            lbMsisdnInfoList.Visible = False
                        End If

                    Else
                        lbMsisdnInfoList.Visible = False
                    End If

            End Select


        End Sub

        Private Sub btnHatBilgiGoster_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHatBilgiGoster.Click

            Select Case rbHatBazli.SelectedValue

                Case "0" 'Tümü

                    Dim dt As DataTable = New DataTable
                    dt.Columns.Add(New DataColumn("MSISDN", GetType(String)))
                    dt.Columns.Add(New DataColumn("STATUS", GetType(String)))


                    For Each li As ListItem In lbMsisdnInfoList.Items

                        Dim dtRow As DataRow = dt.NewRow()
                        dtRow.Item("MSISDN") = li.Value
                        dtRow.Item("STATUS") = li.Text
                        dt.Rows.Add(dtRow)

                    Next

                    Session("RTAO_Selected_MSISDN_INFO") = dt

                Case "1" 'İşlem için seçilenler

                    Session("RTAO_Selected_MSISDN_INFO") = Session("RTML_Selected_MSISDN")

                Case "2" 'Seçim Yapılanlar

                    Dim dt As DataTable = New DataTable
                    dt.Columns.Add(New DataColumn("MSISDN", GetType(String)))
                    dt.Columns.Add(New DataColumn("STATUS", GetType(String)))

                    For Each li As ListItem In lbMsisdnInfoList.Items

                        If li.Selected Then

                            Dim dtRow As DataRow = dt.NewRow()
                            dtRow.Item("MSISDN") = li.Value
                            dtRow.Item("STATUS") = li.Text
                            dt.Rows.Add(dtRow)
                        End If

                    Next

                    Session("RTAO_Selected_MSISDN_INFO") = dt

                Case "3" 'Msisdn

                    If Trim(tbHatMsisdn.Text) = "" Then
                        Message = "alert('Lütfen MSISDN giriniz!');"
                        Return
                    ElseIf Not IsNumeric(Trim(tbHatMsisdn.Text)) Then
                        Message = "alert('MSISDN numerik bir değer olmalıdır!');"
                        Return
                    ElseIf Trim(tbHatMsisdn.Text).Length <> 10 Then
                        Message = "alert('MSISDN 10 hane olmalıdır!');"
                        Return
                    ElseIf lbMsisdnInfoList.Items.FindByValue(Trim(tbHatMsisdn.Text)) Is Nothing Then
                        Message = "alert('Numara şirkete ait değildir!');"
                        Return
                    End If

                    Dim dt As DataTable = New DataTable
                    dt.Columns.Add(New DataColumn("MSISDN", GetType(String)))
                    dt.Columns.Add(New DataColumn("STATUS", GetType(String)))
                    Dim dtRow As DataRow = dt.NewRow()
                    dtRow.Item("MSISDN") = tbHatMsisdn.Text
                    dtRow.Item("STATUS") = tbHatMsisdn.Text
                    dt.Rows.Add(dtRow)
                    Session("RTAO_Selected_MSISDN_INFO") = dt

                Case "4" 'Seçilerden Seçilenler

                    Dim dt As DataTable = New DataTable
                    dt.Columns.Add(New DataColumn("MSISDN", GetType(String)))
                    dt.Columns.Add(New DataColumn("STATUS", GetType(String)))

                    For Each li As ListItem In lbMsisdnInfoList.Items

                        If li.Selected Then

                            Dim dtRow As DataRow = dt.NewRow()
                            dtRow.Item("MSISDN") = li.Value
                            dtRow.Item("STATUS") = li.Text
                            dt.Rows.Add(dtRow)
                        End If

                    Next

                    Session("RTAO_Selected_MSISDN_INFO") = dt

            End Select

            Dim myDiv As HtmlControl = Page.FindControl("myDiv")
            myDiv.Controls.Clear()
            renderContractBasedInfo()

        End Sub



        Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender


            'renderContractBasedInfo()

        End Sub


        Private Sub btnTeklifVermeme_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTeklifVermeme.Click

            'If tbSrNumber.Text = "" Then
            '    Message = "alert('SR Number giriniz!');"
            '    Message += "document.getElementById('tbSrNumber').focus();"
            '    Return
            'End If

            If ddEvrakDurumu.SelectedValue = -1 Then

                Message = "alert('Evrak Durumu seçiniz!');"
                Message += "document.getElementById('ddEvrakDurumu').focus();"
                Return

            ElseIf ddlRetNedeni.SelectedValue = -1 Then

                Message = "alert('Retention Nedeni seçiniz!');"
                Message += "document.getElementById('ddlRetNedeni').focus();"
                Return

            ElseIf ddlAramaTipi.SelectedValue = 0 Then

                Message = "alert('Arama Tipi seçiniz!');"
                Message += "document.getElementById('ddlAramaTipi').focus();"
                Return

            End If

            Dim p_linecancel As Integer = -1
            Dim p_infodealer As String = "NULL"
            Dim p_srnumber As String = Session("rtao_srnumber")
            Dim p_custcode As String = "NULL"
            Dim p_msisdn As String = "NULL"
            Dim p_retention_id As Integer = -1

            Dim p_errorCode As String = "0"
            Dim p_errorMessage As String = "NULL"
            Dim p_errorDetail As String = "NULL"
            Dim p_errorType As String = "NULL"
            Dim p_tid As String = "NULL"
            Dim p_transactiondate As String = DateTime.Now.ToString("MM'/'dd'/'yyyy HH:mm:ss")
            Dim p_calltype As String = "NULL"

            Dim p_customer_id As Integer = CInt(Session("rtao_customerid"))

            Dim p_msisdn_list As String = ":"
            Dim p_hat_iptal As String
            For Each dgi As DataGridItem In dgIslemYapilacakHatlar.Items

                If rbTeklifVermeTipi.SelectedValue = 1 Or rbTeklifVermeTipi.SelectedValue = 3 Then

                    If cbBayiHatIptal.Enabled Then

                        If cbBayiHatIptal.Checked Then
                            p_hat_iptal = "c"
                        Else
                            p_hat_iptal = "n"
                        End If

                    Else
                        p_hat_iptal = "b"
                    End If

                    p_msisdn_list &= dgi.Cells(0).Text & p_hat_iptal & ":"

                ElseIf rbTeklifVermeTipi.SelectedValue = 4 Or rbTeklifVermeTipi.SelectedValue = 2 Then

                    Dim cb As CheckBox = CType(dgi.FindControl("cbHatIptal"), CheckBox)

                    If cb.Enabled Then

                        If cb.Checked Then
                            p_hat_iptal = "c"
                        Else
                            p_hat_iptal = "n"
                        End If
                    Else
                        p_hat_iptal = "b"
                    End If

                    p_msisdn_list &= dgi.Cells(0).Text & p_hat_iptal & ":"

                End If

            Next
            p_msisdn_list &= "-1:"

            Dim p_sr_id As String = Trim(tbSrNumber.Text)
            Dim p_retention_result_id As Integer = CInt(ddlTeklifVermeme.SelectedValue)
            If ddlTeklifVermeme.SelectedValue = 0 Then

                Message = "alert('Teklif Vermeme Nedeni Seçiniz!');"
                Message += "document.getElementById('ddlTeklifVermeme').focus();"
                Return
            End If
            Dim p_offer_id As Integer = 0
            Dim p_dealer_line_cancel As Integer = 0
            If cbBayiHatIptal.Checked Then
                p_dealer_line_cancel = 1
            End If
            Dim p_document_status As Integer = CInt(ddEvrakDurumu.SelectedValue)
            Dim p_retention_reason_id As Integer = CInt(ddlRetNedeni.SelectedValue)
            Dim p_call_type As Integer = CInt(ddlAramaTipi.SelectedValue)
            Dim p_retention_assign_type As Integer = CInt(rbTeklifVermeTipi.SelectedValue)
            Dim p_user_id As String = p_user
            Dim p_user_notes As String = tbUserNotes1.Text
            Dim p_user_profile_id As Integer = CInt(Session("RTML_USER_PROFILE_ID"))
            Dim p_user_email As String = ccapps.persistent.LDAP_Functions.GetMailAdress(Session("user"))
            If p_user_email.IndexOf("@") = -1 Then
                p_user_email = "-1"
            End If
            If p_user_notes = "" Then
                p_user_notes = "-1"
            End If

            Dim dt As DataTable = setRetentionResult(p_sr_id, p_customer_id, Session("rtao_fpm_payer_coid"), p_msisdn_list, p_retention_result_id, p_offer_id, p_dealer_line_cancel, p_document_status, p_retention_reason_id, p_call_type, p_retention_assign_type, Session("rtao_retcustomertypeid"), p_user, p_user_profile_id, p_user_email, p_user_notes, Session("user"))

            Dim dt_b As DataTable = getRetentionSiebelInfo(dt.Rows(0)("RETID"))

            'For Each row As DataRow In dt_b.Rows
            '    For Each col As DataColumn In dt_b.Columns
            '        l_sonuc.Text += row.Item(col) & " "
            '    Next
            '    l_sonuc.Text += Environment.NewLine
            'Next
            p_retention_id = dt.Rows(0)("RETID")
            Dim RejectReason = ""
            Dim OfferName = ""
            Dim SRNumber = dt_b.Rows(0).ItemArray(0)
            Dim OfferStatus = dt_b.Rows(0).ItemArray(12)
            Dim OfferId = dt_b.Rows(0).ItemArray(5)
            Dim RetentionResult = dt_b.Rows(0).ItemArray(4)
            Dim UserId = dt_b.Rows(0).ItemArray(11)
            Dim TransactionDate = p_transactiondate 'dt_b.Rows(0).ItemArray(13)
            Dim ProcessCode = ""
            Dim NMPFlag = dt_b.Rows(0).ItemArray(14)
            Dim OfferType = dt_b.Rows(0).ItemArray(16)
            If OfferStatus = 0 Then
                OfferName = dt_b.Rows(0).ItemArray(6)
            Else
                RejectReason = dt_b.Rows(0).ItemArray(4)
            End If
            Dim MSISDN = "" 'dt_b.Rows(0).ItemArray(3)
            'Dim split As String() = MSISDN.Split(New [Char]() {","})

            'For Each s As String In split
            '    If s.Trim() <> "" Then
            '        Console.WriteLine(s)
            '    End If
            'Next s

            'Dim Description = dt_b.Rows(0).ItemArray(1)
            Dim Description = "SR ID:" & dt_b.Rows(0).ItemArray(0) & "ACIKLAMA:" & dt_b.Rows(0).ItemArray(1) & "CUSTCODE:" & dt_b.Rows(0).ItemArray(2) _
                        & "MSISDN:" & dt_b.Rows(0).ItemArray(3) & "ISLEM SONUCU:" & dt_b.Rows(0).ItemArray(4) & "TEKLIF ID:" & dt_b.Rows(0).ItemArray(5) _
                        & "TEKLIF ADI(Avantajlar):" & dt_b.Rows(0).ItemArray(6) & "KULLANICI ADI:" & dt_b.Rows(0).ItemArray(7) & "ARAMA TIPI:" & dt_b.Rows(0).ItemArray(8) _
                        & "BAYI TALEBI:" & dt_b.Rows(0).ItemArray(9) & "IPTAL SEBEBI:" & dt_b.Rows(0).ItemArray(10) & "USER ID:" & dt_b.Rows(0).ItemArray(11) _
                        & "TEKLIF DURUMU:" & dt_b.Rows(0).ItemArray(12) & "ISLEM TARIHI:" & dt_b.Rows(0).ItemArray(13) & "NUMARA DEGIIKLIGI TALEBI:" & dt_b.Rows(0).ItemArray(14) _
                        & "LINE FREEZe CIKIS TARIHI:" & dt_b.Rows(0).ItemArray(15) & "TEKLIF TIPI:" & dt_b.Rows(0).ItemArray(16)

            Dim requestXML As String = String.Format _
            ( _
                GetFileContent(Server.MapPath("/ccapps/web/Templates/UpdateRetention.XML")), _
                SRNumber, _
                OfferStatus, _
                OfferId, _
                RetentionResult, _
                UserId, _
                TransactionDate, _
                RejectReason, _
                ProcessCode, _
                NMPFlag, _
                OfferType, _
                OfferName, _
                MSISDN, _
                Description _
            )

            Dim doc As New XmlDocument
            doc.LoadXml(requestXML)

            ' Create a new element node.
            Dim newElem As XmlNode
            ' Dim newElem1 As XmlNode
            'newElem = doc.CreateNode(XmlNodeType.Element, "sieb:", "MSISDN", "sieb:")
            'newElem = doc.CloneNode(True)


            Dim i As Integer = 0
            MSISDN = dt_b.Rows(0).ItemArray(3)
            Dim root As XmlElement = doc.DocumentElement.GetElementsByTagName("sieb:ListOfMSISDN").Item(0)
            Dim root1 As XmlElement = doc.DocumentElement.GetElementsByTagName("sieb:MSISDN").Item(0)
            Dim root2 As XmlElement = doc.DocumentElement.GetElementsByTagName("sieb:value").Item(0)
            If MSISDN.Length > 10 Then
                Dim split As String() = MSISDN.Split(New [Char]() {","})
                For Each s As String In split
                    If s.Trim() <> "" And i > 0 Then

                        newElem = root1.CloneNode(True)
                        'newElem.ChildNodes(1).InnerText = s
                        doc.DocumentElement.GetElementsByTagName("sieb:value").Item(0).InnerText = s
                        root.AppendChild(newElem)
                    Else
                        'root1.ChildNodes(1).InnerText = s
                        doc.DocumentElement.GetElementsByTagName("sieb:value").Item(0).InnerText = s
                    End If
                    i += 1
                Next s
            Else
                doc.DocumentElement.GetElementsByTagName("sieb:value").Item(0).InnerText = tbMSISDN.Text
            End If


            ' Console.WriteLine("Display the modified XML document...")
            requestXML = String.Format(doc.OuterXml)

            Dim tdTeklifler As HtmlTableCell = Page.FindControl("tdTeklifler")
            tdTeklifler.Attributes("style") = "PADDING-LEFT: 5px;PADDING-RIGHT: 5px"
            pnlTeklifVermeme.Visible = False
            cbTeklifVermeme.Checked = False
            tbUserNotes1.Text = ""
            pnlUserNotes.Visible = False
            tbUserNotes1.Visible = False
            lblUserNotes.Visible = False
            'If rbTeklifVermeTipi.SelectedValue = 2 Then
            'pnlIslemYapilacakHatlar.Visible = False
            'Else
            pnlIslemYapilacakHatlar.Visible = True
            'End If


            If Session("rtao_msisdn") = "" Then
                dgRetentionHistBind(Session("rtao_customerid"), "-1")
            Else
                dgRetentionHistBind(Session("rtao_customerid"), Session("rtao_msisdn"))
            End If

            dgIslemYapilacakHatlarBind()

            Dim data() As Byte = _
            System.Text.Encoding.Convert _
            ( _
                System.Text.Encoding.GetEncoding("windows-1254"), _
                System.Text.Encoding.UTF8, _
                System.Text.Encoding.GetEncoding("windows-1254").GetBytes(requestXML) _
            )
            '                System.Text.Encoding.GetEncoding("iso-8859-9"), _
            Dim retentionURL As String = persistent.myDBConn.ORAScalar("select parameter_value from EU_BILL.WA_GLOBAL_CONFIGURATION where wa_name='RETENTION' and parameter_name='WebServiceURL'")
            Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(retentionURL)
            request.Method = "POST"
            request.ContentType = "content=""text/xml;charset=iso-8859-9"""
            request.ContentLength = data.Length
            Dim strXML
            Dim reader As IO.StreamReader
            If Trim(tbSrNumber.Text) <> "-1" Then
                If Trim(tbSrNumber.Text) <> "" Then
                    Try
                        Dim streamWriter As New System.IO.StreamWriter(request.GetRequestStream(), System.Text.Encoding.GetEncoding("iso-8859-9"))
                        streamWriter.Write(System.Text.Encoding.GetEncoding("iso-8859-9").GetString(data))
                        streamWriter.Close()

                        Dim response As System.IO.Stream = request.GetResponse().GetResponseStream()
                        Dim responseReader As New IO.StreamReader(response, System.Text.Encoding.GetEncoding("iso-8859-9"))
                        Dim responseXML As String = responseReader.ReadToEnd()


                        Dim ds As New DataSet
                        Dim sr As New System.IO.StringReader(responseXML)
                        Dim XmlDoc As New System.Xml.XmlDocument
                        Dim xmlNodeReader As New System.Xml.XmlNodeReader(XmlDoc)

                        XmlDoc.Load(sr)
                        ds.ReadXml(xmlNodeReader)
                        xmlNodeReader.Close()
                        sr.Close()
                        responseReader.Close()
                        response.Close()
                        streamWriter.Close()
                        Message = "alert('İşlem Tamamlandı! Retention Geçmişine Bakınız!.');"

                        setTransactionLog(p_tid, p_srnumber, p_retention_id, p_custcode, p_msisdn, p_linecancel, p_infodealer, p_calltype, p_user_id, p_errorCode, p_errorMessage, p_errorDetail, p_errorType)


                    Catch ex2 As System.Net.WebException
                        If ex2.Status.ToString.Trim = "ConnectFailure" Then
                            Message = "alert('Teklif verilirken bağlantı hatası oluştu!');"
                            Return
                        Else
                            reader = New IO.StreamReader(ex2.Response.GetResponseStream())
                            strXML = reader.ReadToEnd()
                        End If


                    End Try
                    If strXML <> "" Then

                        Dim ds1 As New DataSet
                        Dim sr1 As New System.IO.StringReader(strXML)
                        Dim XmlDoc1 As New System.Xml.XmlDocument
                        Dim xmlNodeReader1 As New System.Xml.XmlNodeReader(XmlDoc1)

                        XmlDoc1.Load(sr1)
                        ds1.ReadXml(xmlNodeReader1)
                        xmlNodeReader1.Close()
                        sr1.Close()
                        reader.Close()

                        For Each row1 As DataRow In ds1.Tables("mwFault").Rows
                            If row1("errorCode") <> "" Then
                                p_errorCode = row1("errorCode")
                            End If
                            If row1("errorMessage") <> "" Then
                                p_errorMessage = row1("errorMessage")
                            End If
                            If row1("errorDetail") <> "" Then
                                p_errorDetail = row1("errorDetail")
                            End If
                            If row1("errorType") <> "" Then
                                p_errorType = row1("errorType")
                            End If
                            p_tid = row1("tid")
                        Next

                        setTransactionLog(p_tid, p_srnumber, p_retention_id, p_custcode, p_msisdn, p_linecancel, p_infodealer, p_calltype, p_user_id, p_errorCode, p_errorMessage, p_errorDetail, p_errorType)

                        If p_errorCode <> "0" Then
                            ' Message = "alert('Teklif verildi ama siebel Bilgisi Gönderilirken Hata Oluştu!')"
                            Message = "alert(""" & p_errorMessage & """)"
                            Return
                        End If
                    End If
                End If
            End If



        End Sub


        Private Sub dgTeklifler_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgTeklifler.ItemCommand
            Dim p_linecancel As Integer = -1
            Dim p_infodealer As String = "NULL"
            Dim p_srnumber As String = Session("rtao_srnumber")
            Dim p_custcode As String = "NULL"
            Dim p_msisdn As String = "NULL"
            Dim p_retention_id As Integer = -1

            Dim p_errorCode As String = "0"
            Dim p_errorMessage As String = "NULL"
            Dim p_errorDetail As String = "NULL"
            Dim p_errorType As String = "NULL"
            Dim p_tid As String = "NULL"
            Dim p_transactiondate As String = DateTime.Now.ToString("MM'/'dd'/'yyyy HH:mm:ss")
            Dim p_calltype As String = "NULL"

            'Dim x As String
            Dim found As Boolean
            Dim retcount As String
            Dim isWorking As String
            Dim x As Int16

            found = False

            retcount = Session.Item("txtNumofRetentions")
            If retcount = "" Then
                x = 0
            Else
                x = Convert.ToInt16(retcount)
            End If

            isWorking = Session.Item("isWorking")

            If txtNumofRetentions.Text <> retcount Or isWorking <> "" Then
                Message = "alert('Hatalı işlem yaptınız. İşlem sonuçlarını ""Görüntüle"" düğmesine ve ardından ""Retention Geçmişi"" linkine tıklayarak kontrol ediniz.');"
                found = True
            End If

            'If x = "" Then
            'Session.Add("lastreq", System.DateTime.Now.ToString)
            'Message += "no parameter"
            'Else
            'Dim t As DateTime
            'Dim ts As TimeSpan

            't = Convert.ToDateTime(x)

            'ts = System.DateTime.Now.Subtract(t)

            'If ts.Seconds < 5 Then
            ' found = True
            '  Message += "found"
            '   Message = "alert('Talebiniz alınmıştır. Lütfen önceki işleminizin sonlanmasını bekleyiniz.');"
            'Else
            '     Session.Remove("lastreq")
            '      Session.Add("lastreq", System.DateTime.Now.ToString)
            '       Message += "not found"
            '    End If

            ' End If


            If e.CommandName = "Assign" Then
                If lblOfferList.Text = "BNP Suspend - Tanımlanamaz." Then
                    Message = "alert('BNP Suspend Teklif Verilemez.');"
                    Return
                ElseIf lblOfferList.Text = "Suspend - Tanımlanamaz." Then
                    Message = "alert('Suspend Teklif Verilemez.');"
                    Return
                ElseIf lblOfferList.Text = "FRAUD Suspend - Tanımlanamaz." Then
                    Message = "alert('FRAUD Suspend Teklif Verilemez.');"
                    Return
                End If
                'If tbSrNumber.Text = "" Then
                '    initalizeAreas()
                '    Message = "alert('SR Number giriniz.');"
                '    Message += "document.getElementById('tbSrNumber').focus();"
                '    Return
                'End If
                If Trim(tbSrNumber.Text) = "" Then
                    initalizeAreas()
                    Message = "alert('SR Number girilmeden teklif verilemez.');"
                    Message += "document.getElementById('tbSrNumber').focus();"
                    Return
                End If
                If Not found Then
                    If ddEvrakDurumu.SelectedValue = -1 Then

                        dbTekliferReRender()
                        Message = "alert('Evrak Durumu seçiniz!');"
                        Message += "document.getElementById('ddEvrakDurumu').focus();"
                        Return

                    ElseIf ddlRetNedeni.SelectedValue = -1 Then
                        dbTekliferReRender()
                        Message = "alert('Retention Nedeni seçiniz!');"
                        Message += "document.getElementById('ddlRetNedeni').focus();"
                        Return

                    ElseIf ddlAramaTipi.SelectedValue = 0 Then
                        dbTekliferReRender()
                        Message = "alert('Arama Tipi seçiniz!');"
                        Message += "document.getElementById('ddlAramaTipi').focus();"
                        Return

                    End If

                    Session.Add("txtNumofRetentions", x + 1)
                    Session.Add("isWorking", "TRUE")

                    Dim p_sr_id As String = Trim(tbSrNumber.Text)
                    Dim p_customer_id As Integer = CInt(Session("rtao_customerid"))
                    ' Dim p_msisdn As String = "NULL"
                    Dim p_retention_result_id As Integer = 1
                    Dim p_offer_id As Integer = CInt(e.Item.Cells(0).Text)
                    Dim p_dealer_line_cancel As Integer = 0
                    If cbBayiHatIptal.Checked Then
                        p_dealer_line_cancel = 1
                    End If
                    Dim p_document_status As Integer = CInt(ddEvrakDurumu.SelectedValue)
                    Dim p_retention_reason_id As Integer = CInt(ddlRetNedeni.SelectedValue)
                    Dim p_call_type As Integer = CInt(ddlAramaTipi.SelectedValue)
                    Dim p_retention_assign_type As Integer = CInt(rbTeklifVermeTipi.SelectedValue)
                    Dim p_user_id As String = p_user
                    Dim p_user_profile_id As Integer = CInt(Session("RTML_USER_PROFILE_ID"))
                    Dim p_user_notes As String = tbUserNotes1.Text
                    Dim p_msisdn_list As String = ":"

                    Dim p_hat_iptal As String
                    If Trim(p_user_notes) = "" Then
                        p_user_notes = "-1"
                    End If
                    For Each dgi As DataGridItem In dgIslemYapilacakHatlar.Items

                        If rbTeklifVermeTipi.SelectedValue = 1 Or rbTeklifVermeTipi.SelectedValue = 3 Then

                            If cbBayiHatIptal.Enabled Then

                                If cbBayiHatIptal.Checked Then
                                    p_hat_iptal = "c"
                                Else
                                    p_hat_iptal = "n"
                                End If

                            Else
                                p_hat_iptal = "b"
                            End If

                            p_msisdn_list &= dgi.Cells(0).Text & p_hat_iptal & ":"

                        ElseIf rbTeklifVermeTipi.SelectedValue = 4 Or rbTeklifVermeTipi.SelectedValue = 2 Then

                            Dim cb As CheckBox = CType(dgi.FindControl("cbHatIptal"), CheckBox)

                            If cb.Enabled Then

                                If cb.Checked Then
                                    p_hat_iptal = "c"
                                Else
                                    p_hat_iptal = "n"
                                End If
                            Else
                                p_hat_iptal = "b"
                            End If

                            p_msisdn_list &= dgi.Cells(0).Text & p_hat_iptal & ":"

                        End If

                    Next
                    p_msisdn_list &= "-1:"

                    Dim p_user_email As String = ccapps.persistent.LDAP_Functions.GetMailAdress(Session("user"))
                    If p_user_email.IndexOf("@") = -1 Then
                        p_user_email = "-1"
                    End If
                    'Dim pattern As String = "TL"
                    'Dim input As String = e.Item.Cells(1).Text

                    'Dim m As Match = Regex.Match(input, pattern)
                    'If m.Success Then

                    'End If

                    Dim dt As DataTable = setRetentionResult(p_sr_id, p_customer_id, Session("rtao_fpm_payer_coid"), p_msisdn_list, p_retention_result_id, p_offer_id, p_dealer_line_cancel, p_document_status, p_retention_reason_id, p_call_type, p_retention_assign_type, Session("rtao_retcustomertypeid"), p_user, p_user_profile_id, p_user_email, p_user_notes, Session("user"))
                    Dim pbc_exist As Integer = 0
                    Dim lf_exist As Integer = 0
                    Dim pbc_commitment_id As Integer = 0
                    Dim result_type_bc_lf As String
                    If dt.Rows.Count > 0 Then

                        'ddlRetNedeni.Enabled = True
                        p_retention_id = dt.Rows(0)("RETID")


                        Dim dt_b As DataTable = getRetentionSiebelInfo(dt.Rows(0)("RETID"))

                        'For Each row As DataRow In dt_b.Rows
                        '    For Each col As DataColumn In dt_b.Columns
                        '        l_sonuc.Text += row.Item(col) & " "
                        '    Next
                        '    l_sonuc.Text += Environment.NewLine
                        'Next
                        Dim RejectReason = ""
                        Dim OfferName = ""
                        Dim SRNumber = dt_b.Rows(0).ItemArray(0)
                        Dim OfferStatus = dt_b.Rows(0).ItemArray(12)
                        Dim OfferId = dt_b.Rows(0).ItemArray(5)
                        Dim RetentionResult = dt_b.Rows(0).ItemArray(4)
                        Dim UserId = dt_b.Rows(0).ItemArray(11)
                        Dim TransactionDate = p_transactiondate 'dt_b.Rows(0).ItemArray(13)
                        Dim ProcessCode = ""
                        Dim NMPFlag = dt_b.Rows(0).ItemArray(14)
                        Dim OfferType = dt_b.Rows(0).ItemArray(16)
                        ''''SILINECEK'''
                        'If OfferType = "2" Then
                        '    OfferType = "4"
                        'ElseIf OfferType = "3" Then
                        '    OfferType = "2"
                        'ElseIf OfferType = "4" Then
                        '    OfferType = "3"
                        'End If
                        '''SILINECEK BITIS''
                        If OfferStatus = 0 Then
                            OfferName = dt_b.Rows(0).ItemArray(6)
                        Else
                            RejectReason = dt_b.Rows(0).ItemArray(4)
                        End If

                        Dim MSISDN As String



                        ' Dim Description = dt_b.Rows(0).ItemArray(1)
                        Dim Description = "SR ID:" & dt_b.Rows(0).ItemArray(0) & "ACIKLAMA:" & dt_b.Rows(0).ItemArray(1) & "CUSTCODE:" & dt_b.Rows(0).ItemArray(2) _
                      & "MSISDN:" & dt_b.Rows(0).ItemArray(3) & "ISLEM SONUCU:" & dt_b.Rows(0).ItemArray(4) & "TEKLIF ID:" & dt_b.Rows(0).ItemArray(5) _
                      & "TEKLIF ADI(Avantajlar):" & dt_b.Rows(0).ItemArray(6) & "KULLANICI ADI:" & dt_b.Rows(0).ItemArray(7) & "ARAMA TIPI:" & dt_b.Rows(0).ItemArray(8) _
                      & "BAYI TALEBI:" & dt_b.Rows(0).ItemArray(9) & "IPTAL SEBEBI:" & dt_b.Rows(0).ItemArray(10) & "USER ID:" & dt_b.Rows(0).ItemArray(11) _
                      & "TEKLIF DURUMU:" & dt_b.Rows(0).ItemArray(12) & "ISLEM TARIHI:" & dt_b.Rows(0).ItemArray(13) & "NUMARA DEGIIKLIGI TALEBI:" & dt_b.Rows(0).ItemArray(14) _
                      & "LINE FREEZe CIKIS TARIHI:" & dt_b.Rows(0).ItemArray(15) & "TEKLIF TIPI:" & dt_b.Rows(0).ItemArray(16)

                        Dim requestXML As String = String.Format _
                        ( _
                            GetFileContent(Server.MapPath("/ccapps/web/Templates/UpdateRetention.XML")), _
                            SRNumber, _
                            OfferStatus, _
                            OfferId, _
                            RetentionResult, _
                            UserId, _
                            TransactionDate, _
                            RejectReason, _
                            ProcessCode, _
                            NMPFlag, _
                            OfferType, _
                            OfferName, _
                            MSISDN, _
                            Description _
                        )



                        Dim doc As New XmlDocument
                        doc.LoadXml(requestXML)

                        ' Create a new element node.
                        Dim newElem As XmlNode
                        ' Dim newElem1 As XmlNode
                        'newElem = doc.CreateNode(XmlNodeType.Element, "sieb:", "MSISDN", "sieb:")
                        'newElem = doc.CloneNode(True)


                        Dim i As Integer = 0
                        MSISDN = dt_b.Rows(0).ItemArray(3)
                        Dim root As XmlElement = doc.DocumentElement.GetElementsByTagName("sieb:ListOfMSISDN").Item(0)
                        Dim root1 As XmlElement = doc.DocumentElement.GetElementsByTagName("sieb:MSISDN").Item(0)
                        Dim root2 As XmlElement = doc.DocumentElement.GetElementsByTagName("sieb:value").Item(0)
                        If MSISDN.Length > 10 Then
                            Dim split As String() = MSISDN.Split(New [Char]() {","})
                            For Each s As String In split
                                If s.Trim() <> "" And i > 0 Then

                                    newElem = root1.CloneNode(True)
                                    'newElem.ChildNodes(1).InnerText = s
                                    doc.DocumentElement.GetElementsByTagName("sieb:value").Item(0).InnerText = s
                                    root.AppendChild(newElem)
                                Else
                                    ' root1.ChildNodes(1).InnerText = s
                                    doc.DocumentElement.GetElementsByTagName("sieb:value").Item(0).InnerText = s
                                End If
                                i += 1
                            Next s
                        Else
                            doc.DocumentElement.GetElementsByTagName("sieb:value").Item(0).InnerText = tbMSISDN.Text
                        End If


                        ' Console.WriteLine("Display the modified XML document...")
                        requestXML = String.Format(doc.OuterXml)

                        If NVL(dt.Rows(0)("RESULT")) <> "LF" And NVL(dt.Rows(0)("RESULT")) <> "BC" And NVL(dt.Rows(0)("RESULT")) <> "BCO" Then
                            Message = "alert('" & NVL(dt.Rows(0)("RESULT")) & "');"
                        ElseIf NVL(dt.Rows(0)("RESULT")) = "ND" Then
                            Message = "alert('Numara Değişikliği talebiniz alınmıştır.İşleminizi Avea Merkez üzerinden devam edebilirsiniz!');"
                        Else
                            result_type_bc_lf = NVL(dt.Rows(0)("RESULT"))
                        End If
                        pbc_exist = NVL(dt.Rows(0)("PBCEXIST"))
                        lf_exist = NVL(dt.Rows(0)("LFEXIST"))
                        pbc_commitment_id = NVL(dt.Rows(0)("PBCCOMID"))
                        If NVL(dt.Rows(0)("NCEXIST")) = "1" Then
                            Message = "alert('Numara Değişikliği talebiniz alınmıştır.İşleminize Avea Merkez üzerinden devam edebilirsiniz!');"
                        End If


                        Dim data() As Byte = _
                        System.Text.Encoding.Convert _
                        ( _
                            System.Text.Encoding.GetEncoding("windows-1254"), _
                            System.Text.Encoding.UTF8, _
                            System.Text.Encoding.GetEncoding("windows-1254").GetBytes(requestXML) _
                        )

                        Dim retentionURL As String = persistent.myDBConn.ORAScalar("select parameter_value from EU_BILL.WA_GLOBAL_CONFIGURATION where wa_name='RETENTION' and parameter_name='WebServiceURL'")
                        Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(retentionURL)
                        request.Method = "POST"
                        request.ContentType = "content=""text/xml;charset=iso-8859-9"""
                        request.ContentLength = data.Length
                        Dim strXML
                        Dim reader As IO.StreamReader
                        If Trim(tbSrNumber.Text) <> "-1" Then
                            If Trim(tbSrNumber.Text) <> "" Then
                                Try
                                    Dim streamWriter As New System.IO.StreamWriter(request.GetRequestStream(), System.Text.Encoding.GetEncoding("iso-8859-9"))
                                    streamWriter.Write(System.Text.Encoding.GetEncoding("iso-8859-9").GetString(data))
                                    streamWriter.Close()

                                    Dim response As System.IO.Stream = request.GetResponse().GetResponseStream()
                                    Dim responseReader As New IO.StreamReader(response, System.Text.Encoding.GetEncoding("iso-8859-9"))
                                    Dim responseXML As String = responseReader.ReadToEnd()


                                    Dim ds As New DataSet
                                    Dim sr As New System.IO.StringReader(responseXML)
                                    Dim XmlDoc As New System.Xml.XmlDocument
                                    Dim xmlNodeReader As New System.Xml.XmlNodeReader(XmlDoc)

                                    XmlDoc.Load(sr)
                                    ds.ReadXml(xmlNodeReader)
                                    xmlNodeReader.Close()
                                    sr.Close()
                                    responseReader.Close()
                                    response.Close()
                                    streamWriter.Close()

                                    For Each row As DataRow In ds.Tables("ResponseHeader").Rows

                                        p_tid = row("Tid")

                                    Next

                                    Session("RTAO_RETID") = NVL(dt.Rows(0)("RETID"))

                                    setTransactionLog(p_tid, p_srnumber, p_retention_id, p_custcode, p_msisdn, p_linecancel, p_infodealer, p_calltype, p_user_id, p_errorCode, p_errorMessage, p_errorDetail, p_errorType)


                                Catch ex2 As System.Net.WebException
                                    If ex2.Status.ToString.Trim = "ConnectFailure" Then
                                        Message = "alert('Teklif verilirken bağlantı hatası oluştu!');"
                                        Return
                                    Else
                                        Try
                                            reader = New IO.StreamReader(ex2.Response.GetResponseStream())
                                            strXML = reader.ReadToEnd()
                                        Catch
                                            Message = "alert('Teklif verildi ama Hizmet talebi bilgisi gönderilemedi!');"
                                            Return
                                        End Try
                                    End If

                                End Try
                                If strXML <> "" Then
                                    Try
                                        Dim ds1 As New DataSet
                                        Dim sr1 As New System.IO.StringReader(strXML)
                                        Dim XmlDoc1 As New System.Xml.XmlDocument
                                        Dim xmlNodeReader1 As New System.Xml.XmlNodeReader(XmlDoc1)

                                        XmlDoc1.Load(sr1)
                                        ds1.ReadXml(xmlNodeReader1)
                                        xmlNodeReader1.Close()
                                        sr1.Close()
                                        reader.Close()

                                        For Each row1 As DataRow In ds1.Tables("mwFault").Rows
                                            If row1("errorCode") <> "" Then
                                                p_errorCode = row1("errorCode")
                                            End If
                                            If row1("errorMessage") <> "" Then
                                                p_errorMessage = row1("errorMessage")
                                            End If
                                            If row1("errorDetail") <> "" Then
                                                p_errorDetail = row1("errorDetail")
                                            End If
                                            If row1("errorType") <> "" Then
                                                p_errorType = row1("errorType")
                                            End If
                                            p_tid = row1("tid")
                                        Next

                                        setTransactionLog(p_tid, p_srnumber, p_retention_id, p_custcode, p_msisdn, p_linecancel, p_infodealer, p_calltype, p_user_id, p_errorCode, p_errorMessage, p_errorDetail, p_errorType)


                                        If p_errorCode <> "0" Then
                                            ' Message = "alert('Teklif verildi ama Hizmet talebi bilgisi gönderilemedi!')"
                                            Message = "alert(""" & p_errorMessage & """)"
                                            Return
                                        End If
                                    Catch
                                        'Message = "alert('Teklif verildi ama Hizmet talebi bilgisi gönderilemedi!');"
                                        Message = "alert('Teklif verildi ama Hizmet talebi bilgisi gönderilemedi!');"
                                        Return
                                    End Try
                                End If
                            End If
                        End If
                    Else
                        Message = "alert('Teklif verilemedi!');"
                        '    Session.Remove("lastreq")
                        dbTekliferReRender()
                        Session.Remove("isWorking")
                        Session.Add("txtNumofRetentions", x - 1)
                        Return
                    End If

                    Session("RTAO_RETID") = NVL(dt.Rows(0)("RETID"))

                    If pbc_exist = 1 Then

                        Dim result As String() = newPBC(Session("RTAO_RETID"), Session("rtao_custcode"), Session("user"))

                        If result(0) = "OK" Then
                            'pnlPBCIslemTuru.Visible = True
                            'pnlPBC.Visible = False
                            'Message += "alert('PBC Sözleşme Türü Seçiniz!');"
                            'Message += "document.getElementById('tblPBCIslemTuru').focus();"
                            Session("rtao_pbc_id") = result(1)
                            pnlPBCIslemTuru.Visible = False
                            pnlPBC.Visible = True
                            Dim framePBC As HtmlGenericControl = Page.FindControl("framePBC")
                            framePBC.Attributes("src") = "BindingContractCommitment.aspx?Id=" & Session("rtao_pbc_id") & "&OpType=" & rbPBCIslemTuru.SelectedValue & "&RT_COMMITMENT_ID=" & pbc_commitment_id
                            Message = "document.getElementById('tblPbc').focus();"
                        Else
                            Message += "alert('PBC Hatası : " & result(0) & "');"
                            If result_type_bc_lf = "BCO" Then
                                Message += "alert('Retention geçmişine bakınız');"
                            End If
                            pnlPBC.Visible = False
                            pnlPBCIslemTuru.Visible = False
                            Session("rtao_pbc_id") = Nothing
                        End If

                    End If

                    If lf_exist = 1 Then

                        Dim dtLF As DataTable = New DataTable
                        dtLF.Columns.Add(New DataColumn("MSISDN", GetType(String)))
                        dtLF.Columns.Add(New DataColumn("RESULT", GetType(String)))

                        For Each dgi As DataGridItem In dgIslemYapilacakHatlar.Items

                            Dim tb As TextBox = CType(dgi.FindControl("tbLFUygunlugu"), TextBox)

                            If tb.Text Like "Uygun.*" Then

                                Dim dtRow As DataRow = dtLF.NewRow()
                                dtRow.Item("MSISDN") = dgi.Cells(0).Text
                                dtRow.Item("RESULT") = tb.Text
                                dtLF.Rows.Add(dtRow)

                            End If

                        Next

                        If dtLF.Rows.Count > 0 Then

                            pnlLF.Visible = True
                            dgLFMSISDNList.Visible = True
                            dgLFMSISDNList.DataSource = dtLF
                            dgLFMSISDNList.DataBind()

                            Dim iLF As Integer = 0
                            For Each dgi As DataGridItem In dgLFMSISDNList.Items

                                Dim tb As TextBox = CType(dgi.FindControl("tbResult"), TextBox)

                                tb.Text = dtLF.Rows(iLF)("RESULT")

                                Dim cb As CheckBox = CType(dgi.FindControl("cbSec"), CheckBox)
                                cb.Checked = True

                                iLF += 1

                            Next

                            Message += "alert('Line Freeze İşlemi Yapınız!');"
                            Message += "document.getElementById('btnFreezeEt').focus();"
                            chkSMSInform.Checked = False
                            lblDigerGSM.Enabled = False
                            tbDigerGsm.Enabled = False
                            tbDigerGsm.Text = ""

                        Else
                            pnlLF.Visible = False
                            dgLFMSISDNList.Visible = False
                            Message += "alert('Line Freeze İşlemine uygun abone bulunmamaktadır!');"
                        End If

                    End If

                End If ' found = true


                dgTekliflerBind(ddEvrakDurumu.SelectedValue)

                If Session("rtao_msisdn") = "" Then
                    dgRetentionHistBind(Session("rtao_customerid"), "-1")


                Else
                    dgRetentionHistBind(Session("rtao_customerid"), Session("rtao_msisdn"))
                End If

                dgIslemYapilacakHatlarBind()

            ElseIf e.CommandName = "Detail" Then

                RegisterScript("openOfferDetails('RetentionToolOfferDetails.aspx?OFFERID=" & e.Item.Cells(0).Text & "')")

            End If

            Session.Remove("isWorking")

        End Sub

        Private Sub cbTeklifVermeme_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbTeklifVermeme.CheckedChanged
            If cbTeklifVermeme.Checked Then

                Dim tdTeklifler As HtmlTableCell = Page.FindControl("tdTeklifler")
                tdTeklifler.Attributes("style") = "DISPLAY: none;PADDING-LEFT: 5px;PADDING-RIGHT: 5px"
                pnlTeklifVermeme.Visible = True
                pnlUserNotes.Visible = True
                tbUserNotes1.Visible = True
                lblUserNotes.Visible = True
                pnlIslemYapilacakHatlar.Visible = False

            Else

                Dim tdTeklifler As HtmlTableCell = Page.FindControl("tdTeklifler")
                tdTeklifler.Attributes("style") = "PADDING-LEFT: 5px;PADDING-RIGHT: 5px"
                pnlTeklifVermeme.Visible = False
                'If rbTeklifVermeTipi.SelectedValue = 2 Then
                'pnlIslemYapilacakHatlar.Visible = False
                'Else
                pnlIslemYapilacakHatlar.Visible = True
                'End If

            End If
        End Sub

        Private Sub btnFreezeEt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFreezeEt.Click


            If Me.chkSMSInform.Checked Then
                If tbDigerGsm.Text.Trim().Length = 0 Then
                    Message = "alert('Diğer GSM No girmelisiniz!');"
                    Message += "document.getElementById('tbDigerGsm').focus();"
                    Return
                ElseIf Not IsNumeric(tbDigerGsm.Text) Then
                    Message = "alert('Diğer GSM No numerik bir değer olmalıdır!');"
                    Message += "document.getElementById('tbDigerGsm').focus();"
                    Return
                ElseIf tbDigerGsm.Text.Trim().Length <> 10 Then

                    Message = "alert('Diğer GSM No 10 hane olmalıdır!');"
                    Message += "document.getElementById('tbDigerGsm').focus();"
                    Return
                ElseIf tbDigerGsm.Text.Trim().Substring(0, 1) <> "5" Then

                    Message = "alert('Diğer GSM No 5 ile başlıyor olmalıdır');"
                    Message += "document.getElementById('tbDigerGsm').focus();"
                    Return
                End If
            End If

            Dim selected_count As Integer = 0
            Dim p_msisdn As String
            Dim p_duration As Integer
            Dim p_contact_events As Integer = 3
            Dim p_contact_msisdn As String
            Dim p_send_inform_sms As Integer

            If chkSMSInform.Checked Then
                p_send_inform_sms = 1
                p_contact_msisdn = tbDigerGsm.Text.Trim()
            Else
                p_send_inform_sms = 0
                p_contact_msisdn = "-1"
            End If

            Dim p_retention_id As Integer = Session("RTAO_RETID")
            For Each dgi As DataGridItem In dgLFMSISDNList.Items

                Dim cb As CheckBox = CType(dgi.FindControl("cbSec"), CheckBox)
                If cb.Checked Then

                    selected_count = 1

                    p_msisdn = dgi.Cells(1).Text

                    Dim ddl As DropDownList = CType(dgi.FindControl("ddlLFDuration"), DropDownList)

                    p_duration = ddl.SelectedValue

                    Dim tb As TextBox = CType(dgi.FindControl("tbResult"), TextBox)

                    If tb.Text Like "Uygun.*" Then

                        Dim result As String() = newLineFreeze(p_msisdn, p_duration, p_contact_events, p_contact_msisdn, p_send_inform_sms, p_user, p_retention_id, Session("user"))
                        tb.Text = result(0)

                    End If
                End If
            Next

            If selected_count = 0 Then

                Message += "alert('İşlem yapılacak numara seçiniz!');"
                Return
            Else

                dgTekliflerBind(ddEvrakDurumu.SelectedValue)

            End If

            Message += "document.getElementById('btnFreezeEt').focus();"

        End Sub

        Private Sub chkSMSInform_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkSMSInform.CheckedChanged
            If chkSMSInform.Checked Then

                lblDigerGSM.Enabled = True
                tbDigerGsm.Enabled = True

            Else

                lblDigerGSM.Enabled = False
                tbDigerGsm.Enabled = False
                tbDigerGsm.Text = ""

            End If

            Message = "document.getElementById('tblLF').focus();"

        End Sub

        Private Sub btnTeklifVermeme_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnTeklifVermeme.PreRender

        End Sub

        Private Sub ddEvrakDurumu_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddEvrakDurumu.SelectedIndexChanged
            dgTekliflerBind(ddEvrakDurumu.SelectedValue)
        End Sub


        Private Sub ddEvrakDurumu_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddEvrakDurumu.PreRender

        End Sub

        Private Sub btnDeactCezaHesapla_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeactCezaHesapla.Click

            Dim p_msisdn_list As String = ":"
            For Each dgi As DataGridItem In dgIslemYapilacakHatlar.Items
                p_msisdn_list &= dgi.Cells(0).Text & ":"
            Next
            p_msisdn_list &= "-1:"

            Dim result As String() = getDeactPanaltyAmount(Session("rtao_customerid"), Session("rtao_fpm_payer_coid"), p_user, rbTeklifVermeTipi.SelectedValue, p_msisdn_list, Session("user"))

            tbDeaktivasyonCezaTutari.Text = result(0)

        End Sub




        Private Sub cbBayiHatIptal_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbBayiHatIptal.CheckedChanged


            If rbTeklifVermeTipi.SelectedValue = 4 Or rbTeklifVermeTipi.SelectedValue = 2 Then

                If Not (Session("RTML_Selected_MSISDN") Is Nothing) Then
                    Dim dt As DataTable = Session("RTML_Selected_MSISDN")

                    If dt.Rows.Count > 0 Then

                        For Each dgi As DataGridItem In dgIslemYapilacakHatlar.Items

                            Dim cb As CheckBox = CType(dgi.FindControl("cbHatIptal"), CheckBox)
                            If cb.Enabled Then
                                cb.Checked = cbBayiHatIptal.Checked
                            End If
                        Next
                    End If
                End If
            End If

        End Sub


        Private Sub btnPBCIslemTuru_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPBCIslemTuru.Click
            pnlPBCIslemTuru.Visible = False
            pnlPBC.Visible = True
            Dim framePBC As HtmlGenericControl = Page.FindControl("framePBC")


            If rbPBCIslemTuru.SelectedValue = "0" Then
                framePBC.Attributes("src") = "BindingContract.aspx?Id=" & Session("rtao_pbc_id")
            Else
                framePBC.Attributes("src") = "BindingContractCommitment.aspx?Id=" & Session("rtao_pbc_id") & "&OpType=" & rbPBCIslemTuru.SelectedValue
            End If

            Message = "document.getElementById('tblPbc').focus();"

        End Sub


        'Private Sub dgRetentionHist_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgRetentionHist.ItemCommand

        '    If e.CommandName = "SiebelInfo" Then

        '        Message = "openSiebelDetails('RetentionToolRetentionSiebelDetails.aspx?RetentionID=" & e.Item.Cells(0).Text & "')"

        '    End If

        'End Sub

        Private Sub cbHepsiniSec_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbHepsiniSec.CheckedChanged
            If rbTeklifVermeTipi.SelectedValue <> 1 Then

                If Not (Session("RTML_Selected_MSISDN") Is Nothing) Then
                    Dim dt As DataTable = Session("RTML_Selected_MSISDN")

                    If dt.Rows.Count > 0 Then

                        For Each dgi As DataGridItem In dgIslemYapilacakHatlar.Items

                            Dim cb As CheckBox = CType(dgi.FindControl("cbHatIptal"), CheckBox)
                            If cb.Enabled Then
                                cb.Checked = cbHepsiniSec.Checked
                            End If
                        Next
                    End If
                End If
            End If
        End Sub

        Private Function getHighLevelCustcode(ByVal Custcode As String) As String

            Dim retValCustCode As String = String.Empty
            '------Girilen Msisdn veya Custocode'a göre abonenin custcode'unu  getiren sorgu
            'Dim query As String = "select nvl(substr('" & Custcode & "', 0, instr('" & Custcode & "', '.', 3)-1),'" & Custcode & "') from dual "
            Dim query As String = "select nvl(substr('" & Custcode & "', 0, instr('" & Custcode & "', '.',1,3)-1),'" & Custcode & "') from dual"
            'LOGLAMA
            'Dim dtCustomer As DataTable = persistent.myDBConn.myORATable(query)
            Dim dtCustomer As DataTable

            dtCustomer = persistent.myDBConn.myORATable(query)

            dtCustomer = persistent.myDBConn.myORATable_LOG(query, "", "", "", Custcode, "select(getHighLevelCustcode)", "RetentionToolAssignOffer", Session("user").ToString())


            If dtCustomer.Rows.Count > 0 AndAlso Not IsDBNull(dtCustomer.Rows(0)(0)) Then
                retValCustCode = dtCustomer.Rows(0)(0)
            End If
            Return retValCustCode
        End Function
    End Class

End Namespace